mysql日期加减函数(mysql日期相减函数)
大家好,今日小周来为大家解答以上的问题。mysql日期加减函数,mysql日期相减函数很多人还不知道,现在让我们一起来看看吧!
1、mysql> SELECT DATE_ADD(-> '2000-01-01 00:00:00.000000',-> INTERVAL 2 MONTH) A,-> DATE_SUB(-> '2000-01-01 00:00:00.000000',-> INTERVAL 2 MONTH) B;+---------------------+---------------------+| A | B |+---------------------+---------------------+| 2000-03-01 00:00:00 | 1999-11-01 00:00:00 |+---------------------+---------------------+1 row in set (0.00 sec)用这个 DATE_ADD / DATE_SUB 函数,不知道能否解决 楼主这个问题.where datediff(mm,logtime,getDate())切换成WHERE logtime > DATE_SUB(CURRENT_DATE(), INTERVAL 5 MONTH)AND logtime 逻辑就是 logtime > 今天-5个月 AND logtime -----MySQLADDTIME(日期,时间)或者ADDTIME(时间,时间)DATE_ADD指定日期+ 日/月/周/年DATE_SUB指定日期- 日/月/周/年可选单位参数MICROSECONDSECONDMINUTEHOURDAYWEEKMONTHQUARTERYEAR时间增加mysql> SELECT ADDTIME(-> '2000-01-01 00:00:00.000000',-> '1 2:3:4.000005') A;+----------------------------+| A |+----------------------------+| 2000-01-02 02:03:04.000005 |+----------------------------+1 row in set (0.00 sec)mysql> SELECT ADDTIME(-> '01:00:00.000000',-> '02:03:04.000005') B;+-----------------+| B |+-----------------+| 03:03:04.000005 |+-----------------+1 row in set (0.00 sec)-----MySQLDATEDIFF 只计算到天的单位TIMEDIFF 到毫秒单位mysql> SELECT DATEDIFF (-> '2000-01-01 00:00:00.000000',-> '2000-01-02 05:06:07.000008') A;+------+| A |+------+| -1 |+------+1 row in set (0.00 sec)mysql> SELECT-> TIMEDIFF ('2000-01-01 00:00:00.000000',-> '2000-01-02 05:06:07.000008') A;+------------------+| A |+------------------+| -29:06:07.000008 |+------------------+1 row in set (0.00 sec)mysql> select date_format(now(),'%Y');+-------------------------+| date_format(now(),'%Y') |+-------------------------+| 2009 |+-------------------------+1 row in set (0.00 sec)扩展:%Y:年%c:月%d:日%H:小时%i:分钟%s:秒mysql> select date_format(now(),'%Y-%c-%d %h:%i:%s');+----------------------------------------+| date_format(now(),'%Y-%c-%d %h:%i:%s') |+----------------------------------------+| 2009-8-07 06:59:40 |+----------------------------------------+1 row in set (0.00 sec)---以上,希望对你有所帮助。
本文到这结束,希望上面文章对大家有所帮助。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系 836084111@qq.com 删除。