位置:首頁 > 數據庫 > SQL教學 > SQL WEEK()函數

SQL WEEK()函數

WEEK(date[,mode])

此函數返回日期的周數。雙參數的形式WEEK()允許你指定星期是否開始於周日或周一,以及是否返回值應在範圍從0到53或從1到53。 如果省略了mode參數,係統default_week_format變量的值被使用

Mode 一個星期的第一天 範圍 Week 1 是第一個星期
0 Sunday 0-53 with a Sunday in this year
1 Monday 0-53 with more than 3 days this year
2 Sunday 1-53 with a Sunday in this year
3 Monday 1-53 with more than 3 days this year
4 Sunday 0-53 with more than 3 days this year
5 Monday 0-53 with a Monday in this year
6 Sunday 1-53 with more than 3 days this year
7 Monday 1-53 with a Monday in this year

mysql> SELECT WEEK('1998-02-20');
+---------------------------------------------------------+
| WEEK('1998-02-20')                                      |
+---------------------------------------------------------+
| 7                                                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)