Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

WEEK

Example

Retrieve the week number corresponding to a specific date.

SELECT WEEK(“2017-06-15”);

Definition and Usage

The WEEK() function returns the week number (ranging from 0 to 53) for a specified date.

Syntax

WEEK(datefirstdayofweek)

Parameter Values

Parameter

Description

date

Required: The date or datetime from which to extract the week number.

 firstdayofweek

Optional: Specifies the starting day of the week, which can be any of the following options:

  • 0 – First day of week is Sunday
  • 1 – First day of week is Monday and the first week of the year has more than 3 days
  • 2 – First day of week is Sunday
  • 3 – First day of week is Monday and the first week of the year has more than 3 days
  • 4 – First day of week is Sunday and the first week of the year has more than 3 days
  • 5 – First day of week is Monday
  • 6 – First day of week is Sunday and the first week of the year has more than 3 days
  • 7 – First day of week is Monday

Technical Details

Works in:

 From MySQL version 4.0

More Examples

Example

Retrieve the week number corresponding to a specific date.

SELECT WEEK(“2017-10-25”);

Example

Retrieve the week number for the current date according to the system’s settings.

SELECT WEEK(CURDATE());