小编给大家分享一下mysql中TIMESTAMPDIFF函数怎么用,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
TIMESTAMPDIFF
TIMERSTAMPDIFF语法:
TIMERSTAMPDIFF(interval,datetime_expr1,datetime_expr2)
说明:
该函数是返回datetime_expr1和datetime_expr2之间的整数差,其中单位有interval参数决定,interval的常用参数有:
FRAC_SECOND 时间间隔是毫秒
SECOND 时间间隔是秒
MINUTE 时间间隔是分钟
HOUR 时间间隔是小时
DAY 时间间隔是天
WEEK 时间间隔是周
MOUTH 时间间隔是月
QUARTER 时间间隔是季度
YEAR 时间间隔是年
示例:
MariaDB [(none)]> select timestampdiff(hour,'2018-06-05 09:00:00','2018-06-15 09:00:00');
+-----------------------------------------------------------------+
| timestampdiff(hour,'2018-06-05 09:00:00','2018-06-15 09:00:00') |
+-----------------------------------------------------------------+
| 240 |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)
示例二:
MariaDB [(none)]> select timestampdiff(day,'2018-06-05 09:00:00','2018-06-15 09:00:00');
+----------------------------------------------------------------+
| timestampdiff(day,'2018-06-05 09:00:00','2018-06-15 09:00:00') |
+----------------------------------------------------------------+
| 10 |
+----------------------------------------------------------------+
1 row in set (0.00 sec)
看完了这篇文章,相信你对“mysql中TIMESTAMPDIFF函数怎么用”有了一定的了解,如果想了解更多相关知识,欢迎关注编程网行业资讯频道,感谢各位的阅读!