返回顶部

收藏

mysql datediff 函数返回两个日期之间的秒数

更多

mysql的datediff函数默认返回两个日期之间相差的天数,

例如:

select datediff('2015-11-23', '2015-11-22') as daysDiff

将返回1. 要想返回秒数需要使用下面两个函数配合

SELECT TIME_TO_SEC(TIMEDIFF('2010-08-20 12:01:00', '2010-08-20 12:00:00')) diff;
+------+
| diff |
+------+
|   60 |
+------+
1 row in set (0.00 sec)

或者使用UNIX_TIMESTAMP函数

SELECT UNIX_TIMESTAMP('2010-08-20 12:01:00') - 
       UNIX_TIMESTAMP('2010-08-20 12:00:00') diff;
+------+
| diff |
+------+
|   60 |
+------+
1 row in set (0.00 sec)

标签:mysql,date

收藏

0人收藏

支持

0

反对

0

发表评论