WEEK(date[,first])

Description: Returns the week of the year of date (a date, or date and time) in the range 0 to 53. Without first specified, Sunday is taken as the first day of the week (day 0). With first set to 0, the first day is taken as Sunday, or if set to 1, the first day is taken as Monday.

Examples:

  • DAYNAME('2002-01-01') returns Tuesday.

  • WEEK('2002-01-01') returns 0.

  • WEEK('2002-01-01',0) returns 0.

  • WEEK('2002-01-06',0) returns 1.

  • WEEK('2002-01-01',1) returns 1.

Note that from MySQL 4 onward, WEEK() was changed to return the week number according to the US calendar; if a week started in the previous year, WEEK(date,0) returns 0.

See also: YEARWEEK()

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.