转载自: https://blog.csdn.net/csdn_0_001/article/details/79502200
语法
YEAR(date)
Returns the year for date, in the range 1000 to 9999, or 0 for the “zero” date.
返回日期的年份,范围为1000到9999,或者对于“零”日期返回0。
QUARTER(date)
Returns the quarter of the year for date, in the range 1 to 4.
返回日期的一年中的季度,范围为1到4。
MONTH(date)
Returns the month for date, in the range 1 to 12 for January to December, or 0 for dates such as ‘0000-00-00’ or ‘2008-00-00’ that have a zero month part.
返回日期的月份,1月至12月的范围为1至12,对于包含月份为零的日期(如“0000-00-00”或“2008-00-00”),返回0。
WEEK(date[,mode])
This function returns the week number for date. The two-argument form of WEEK() enables you to specify whether the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or from 1 to 53. If the mode argument is omitted, the value of the default_week_format system variable is used.
此函数返回日期的周号。 WEEK()的双参数使您能够指定星期是从星期天还是星期一开始,以及返回值是在0到53还是从1到53的范围内。如果省略mode参数,则值 使用了default_week_format系统变量。
实例
SELECT YEAR('2011-12-13'); # 2011
SELECT QUARTER('2011-12-13'); # 4
SELECT MONTH('2011-12-13'); # 12
SELECT WEEK('2011-12-31'); # 52
SELECT WEEK('2004-12-31',0); # 52
SELECT WEEK('2004-12-31',1); # 53
SELECT WEEK('2004-01-01',0); # 0
SELECT WEEK('2004-01-01',1); # 1