MySQL时间差函数TIMESTAMPDIFF,获取两个时间之间的月份、天数等

一、获取两个时间之间的天数

select TIMESTAMPDIFF(DAY, '2020-03-20 23:59:00', '2020-03-25 00:00:00') as diff;

MySQL时间差函数TIMESTAMPDIFF,获取两个时间之间的月份、天数等_第1张图片

二、获取 两个时间之间的月份

select TIMESTAMPDIFF(month, '2020-01-20 23:59:00', '2020-03-25 00:00:00') as diff;

MySQL时间差函数TIMESTAMPDIFF,获取两个时间之间的月份、天数等_第2张图片

三、获取两个时间之间的 

select TIMESTAMPDIFF(HOUR, '2020-03-23 23:59:00', '2020-03-25 00:00:00') as diff;

MySQL时间差函数TIMESTAMPDIFF,获取两个时间之间的月份、天数等_第3张图片

select TIMESTAMPDIFF(minute, '2020-01-20 23:59:00', '2020-03-25 00:00:00') as diff;
select TIMESTAMPDIFF(second, '2020-01-20 23:59:00', '2020-03-25 00:00:00') as diff;
select TIMESTAMPDIFF(year, '2020-01-20 23:59:00', '2020-03-25 00:00:00') as diff;

 

你可能感兴趣的:(mysql)