- 时间:2020-10-11 21:50 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:MySQL 日期时间函数常用总结
获得当前日期+时间(date + time)1.1 函数:now()
[list=1][/list]
相关函数:current_timestamp(),localtime(),localtimestamp()
举例说明:
[img]http://files.jb51.net/file_images/article/201206/201206121728382.jpg[/img]
2. 获得当前日期(date)
函数:curdate()
相关函数:current_date(),current_date
举例说明:
[img]http://files.jb51.net/file_images/article/201206/201206121728383.jpg[/img]
3. 获得当前时间(time)
函数:curtime()
相关函数:current_time(),current_time
举例说明
[img]http://files.jb51.net/file_images/article/201206/201206121728384.jpg[/img]
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 天