Mysql Weekofyear Function

MySQL: WEEKOFYEAR Function

This tutorial explains how to use the MySQL WEEKOFYEAR function with syntax and examples.

Description

The MySQL WEEKOFYEAR function returns week of the year for a date value.

Syntax

The syntax for the WEEKOFYEAR function in MySQL is:

WEEKOFYEAR( date_value )

Parameters or Arguments

date_value

A date or datetime value from which to extract the week of the year.

Note

  • The WEEKOFYEAR function returns the week of the year (a number from 1 to 53) given a date value.
  • The WEEKOFYEAR function assumes that the first day of the week is Monday and the first week has more than 3 days.
  • The WEEKOFYEAR function returns the same as the WEEK function with the syntax of WEEK(date_value,3).

Applies To

The WEEKOFYEAR function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let's look at some MySQL WEEKOFYEAR function examples and explore how to use the WEEKOFYEAR function in MySQL.

For example:

mysql> SELECT WEEKOFYEAR('2014-01-01');
Output: 1

mysql> SELECT WEEKOFYEAR('2014-02-28');
Output: 9

mysql> SELECT WEEKOFYEAR('2014-12-28');
Output: 52

This last WEEKOFYEAR example would display the week of the year for the current system date (current system date is returned by the CURDATE function).

mysql> SELECT WEEKOFYEAR(CURDATE());