关于MySQL的几个日期时间函数
select now(); 返回当前的日期时间
select curdate(); 返回当前日期
select curtime(); 返回当前时间
select week(date); 返回日期date为一年中的第几周
select monthname(date); 返回日期date的英文月份名称
select date_add(date,INTERVAL expr type); 返回与所给日期date相差INTERVAL时间段的日期
举例:select now() current,date_add(now(),INTERVAL 31 day) after31days, date_add(now(), INTERVAL '1_2' year_month) after_oneyear_twomonth;
结果:current after31days after_oneyear_twomonth
2010-04-07 18:08:36 2010-05-08 18:08:36 2011-06-07 18:08:36
select datediff(date1,date2); 返回两个日期之间相差的天数 date1表示较大的日期,date2表示较小的日期
本文介绍了MySQL中常用的日期时间函数,包括获取当前日期时间、计算日期间隔等实用操作,并通过实例展示了这些函数的具体用法。
1033

被折叠的 条评论
为什么被折叠?



