TIMESTAMPDIFF:后面的时间减去前面的时间
select
-- 时间相差不到24小时不算一天
TIMESTAMPDIFF(DAY,'2017-06-02 00:00:00','2017-06-03') day1, -- 1
TIMESTAMPDIFF(DAY,'2017-06-02 00:00:01','2017-06-03') day2, -- 0
TIMESTAMPDIFF(DAY,'2017-06-02 11:00:11','2017-06-03 11:00:11') day3, -- 1
TIMESTAMPDIFF(DAY,'2017-06-02 11:00:11','2017-06-03 14:00:11') day4, -- 1
TIMESTAMPDIFF(DAY,'2017-06-02 11:00:11','2017-06-03 10:00:11') day5 -- 0
DATEDIFF:前面的时间减去后面的时间
select
-- 只取前面日期部分进行计算
DATEDIFF('2017-06-03','2017-06-02 00:00:00') day1, -- 1
DATEDIFF('2017-06-03','2017-06-02 00:00:01') day2, -- 1
DATEDIFF('2017-06-03 11:00:11','2017-06-02 11:00:11') day3, -- 1
DATEDIFF('2017-06-03 14:00:11','2017-06-02 11:00:11') day4, -- 1
DATEDIFF('2017-06-03 10:00:11','2017-06-02 11:00:11') day5 -- 1
在这里插入图片描述