1 2 3 4 5 6 7
| -- 计算两个日期之间的天数差,datediff(end_date,start_date)->返回天数 11 select datediff('2020-08-14 18:08:00','2020-08-03 20:09:10') as diff; -- 11 -- 计算两个日期之间的分钟差,timestampdiff(interval,start_date,end_date)->返回interval参数的值 -- interval可取值:SECOND ,MINUTE ,HOUR ,DAY , WEEK ,MONTH, QUARTER ,YEAR select timestampdiff(second ,'2020-08-03 20:09:10','2020-08-14 18:08:00') as sdiff; -- 943130 select timestampdiff(YEAR ,'2020-08-03 20:09:10','2021-08-14 18:08:00') as sdiff; -- 1
|