Mega Code Archive

 
Categories / MySQL Tutorial / Date Time Functions
 

WEEK(date[,mode]) returns the week number for date

The mode specifies whether the week starts on Sunday or Monday. If the mode argument is omitted, the value of the default_week_format system variable is used. The mode could be 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 mysql> mysql> SELECT WEEK('1998-02-20'); +--------------------+ | WEEK('1998-02-20') | +--------------------+ |                  7 | +--------------------+ 1 row in set (0.00 sec) mysql> SELECT WEEK('1998-02-20',0); +----------------------+ | WEEK('1998-02-20',0) | +----------------------+ |                    7 | +----------------------+ 1 row in set (0.00 sec) mysql> SELECT WEEK('1998-02-20',1); +----------------------+ | WEEK('1998-02-20',1) | +----------------------+ |                    8 | +----------------------+ 1 row in set (0.00 sec) mysql> SELECT WEEK('1998-12-31',1); +----------------------+ | WEEK('1998-12-31',1) | +----------------------+ |                   53 | +----------------------+ 1 row in set (0.02 sec) mysql> SELECT WEEK('2000-01-01',2); +----------------------+ | WEEK('2000-01-01',2) | +----------------------+ |                   52 | +----------------------+ 1 row in set (0.00 sec) mysql>