MYSQL函数YEAR,MONTH,QUARTER,WEEK用法

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
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-095d4a0b23.css" rel="stylesheet">
                </div>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值