目录

MySQL WEEK() 函数

示例

返回日期的周数:

SELECT WEEK("2017-06-15");
亲自试一试 »

定义和用法

WEEK() 函数返回给定日期的周数(0 到 53 之间的数字)。

语法

WEEK( date, firstdayofweek)

参数值

Parameter Description
date Required.  The date or datetime to extract the week number form
firstdayofweek

Optional. Specifies what day the week starts on. Can be one of the following:

  • 0 - First day of week is Sunday
  • 1 - First day of week is Monday and the first week of the year has more than 3 days
  • 2 - First day of week is Sunday
  • 3 - First day of week is Monday and the first week of the year has more than 3 days
  • 4 - First day of week is Sunday and the first week of the year has more than 3 days
  • 5 - First day of week is Monday
  • 6 - First day of week is Sunday and the first week of the year has more than 3 days
  • 7 - First day of week is Monday

技术细节

工作于: 从 MySQL 4.0 开始

更多示例

示例

返回日期的周数:

SELECT WEEK("2017-10-25");
亲自试一试 »

示例

返回当前系统日期的周数:

SELECT WEEK(CURDATE());
亲自试一试 »