-> 53 

If a date falls in the last week of the previous year, MySQL returns 0  if you do not use 2 , 3 , 6 , or 7  as the optional mode  argument: 

mysql> SELECT YEAR(’2000-01-01’), WEEK(’2000-01-01’,0); -> 2000, 0 

One might argue that WEEK()  should return 52  because the given date actually occurs in the 52nd week of 1999. WEEK()  returns 0  instead so that the return value is “the week number in the given year.”  This makes use of the WEEK()  function reliable when combined with other functions that extract a date part from a date. 

If you prefer a result evaluated with respect to the year that contains the first day of the week for the given date, use 0 , 2 , 5 , or 7  as the optional mode  argument. 

mysql> SELECT WEEK(’2000-01-01’,2); -> 52 

Alternatively, use the YEARWEEK()  function: 

mysql> SELECT YEARWEEK(’2000-01-01’); -> 199952 mysql> SELECT MID(YEARWEEK(’2000-01-01’),5,2); -> ’52’ 

• WEEKDAY( date ) 

Returns the weekday index for date  ( 0  = Monday, 1  = Tuesday, … 6  = Sunday). 

mysql> SELECT WEEKDAY(’2008-02-03 22:23:00’); -> 6 mysql> SELECT WEEKDAY(’2007-11-06’); -> 1 

• WEEKOFYEAR( date ) 

Returns the calendar week of the date as a number in the range from 1  to 53 . WEEKOFYEAR()  is a compatibility function that is equivalent to WEEK( date ,3) . 

mysql> SELECT WEEKOFYEAR(’2008-02-20’); -> 8 

• YEAR( date ) 

Returns the year for date , in the range 1000  to 9999 , or 0  for the “zero”  date. 

mysql> SELECT YEAR(’1987-01-01’); -> 1987 

• YEARWEEK( date ) , YEARWEEK( date , mode ) 

Returns year and week for a date. The year in the result may be different from the year in the date argument for the first and the last week of the year. 

The mode  argument works exactly like the mode  argument to WEEK() . For the single-argument syntax, a mode  value of 0 is used. Unlike WEEK() , the value of default_week_format  does not influence YEARWEEK() . 

mysql> SELECT YEARWEEK(’1987-01-01’); 

