六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 61|回复: 0

MySQL日期时间函数常用总结

[复制链接]

升级  11.75%

405

主题

405

主题

405

主题

探花

Rank: 6Rank: 6

积分
1235
 楼主| 发表于 2012-12-10 13:12:29 | 显示全部楼层 |阅读模式
<div id="cnblogs_post_body">

  • 获得当前日期+时间(date + time)1.1    函数:now()


  • 相关函数:current_timestamp(),localtime(),localtimestamp()
  • 举例说明:



    2. 获得当前日期(date)

  • 函数:curdate()
  • 相关函数:current_date(),current_date
  • 举例说明:



    3. 获得当前时间(time)

  • 函数:curtime()
  • 相关函数:current_time(),current_time
  • 举例说明


    4. MySQL dayof…


    • 函数:dayofweek(), dayofmonth(), dayofyear()分别返回日期参数,在一周、一月、一年中的位置。
    • 举例说明
    • set @dt = '2008-08-08';
    • select dayofweek(@dt); -- 6
    • select dayofmonth(@dt); -- 8
    • select dayofyear(@dt); -- 221
    • 日期‘2008-08-08′ 是一周中的第6 天(1 = Sunday, 2 = Monday, …, 7 = Saturday)
    • 一月中的第8 天;一年中的第221 天

您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表