1. 程式人生 > >mysql時間差函式datediff和TIMESTAMPDIFF

mysql時間差函式datediff和TIMESTAMPDIFF

7.時間差函式:datediff(date1,date2)
(1)select datediff(now(), now());#0
(2)select datediff('2018-04-22 23:59:00', '2018-04-20 00:00:00');#2
8.時間差函式:TIMESTAMPDIFF
select TIMESTAMPDIFF(DAY, '2018-04-20 00:00:00', '2018-04-22 23:59:00');#2
select TIMESTAMPDIFF(HOUR, '2018-04-20 00:00:00', '2018-04-22 23:00:00');#71
select TIMESTAMPDIFF(MINUTE, '2018-04-20 00:00:00'
, '2018-04-22 23:00:00');
#4260 select last_day(curdate());#返回當月最後一天 select date_add(last_day(curdate()), interval 1 day);#返回下月第一天 select day(curdate());#當天為當月的第幾天 select date_add(curdate(), interval 1-(day(curdate())) day);#當月第一天