MySQL WEEK() Function

The WEEK() function in MySQL extracts the week number from a date value. This is particularly useful for tasks involving weekly data analysis or reporting.



WEEK(): Definition and Usage

WEEK() returns an integer representing the week number within the year. The week number ranges from 0 to 53. You can optionally specify which day of the week marks the beginning of the week (Sunday or Monday).

Syntax

Syntax

WEEK(date, firstdayofweek)
      

Parameter Values

Parameter Description
date The date or datetime value. This is required.
firstdayofweek (Optional) Specifies the first day of the week. If omitted, it defaults to Sunday. Values:
  • 0: Sunday
  • 1: Monday (first week has > 3 days)
  • 2: Sunday
  • 3: Monday (first week has > 3 days)
  • 4: Sunday (first week has > 3 days)
  • 5: Monday
  • 6: Sunday (first week has > 3 days)
  • 7: Monday

Examples

Week Number for a Specific Date

This query finds the week number for June 15th, 2017.

Syntax

SELECT WEEK("2017-06-15");
      
Output

24
      

Week Number for Another Date

Finding the week number for October 25th, 2017.

Syntax

SELECT WEEK("2017-10-25");
      
Output

43
      

Week Number for Today

Getting the current week number.

Syntax

SELECT WEEK(CURDATE());
      
Output

(The current week number, 0-53)