0

可能重复:
MYSQL - 日期时间到秒

如果我在 mysql 表中有一个 datetime 列,我如何才能以秒为单位获得 NOW() 和该列之间的差异?

4

2 回答 2

5

TIMEDIFF你可以在几秒钟内得到差异

    SELECT TIME_TO_SEC(TIMEDIFF('2007-01-09 10:24:46','2007-01-09 10:23:46'));

或这个

SELECT DATEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01') * 24*60*60;
// result: 86400 the difference in seconds for days.

或者:

 SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00'); 
 // result: 79259  the difference in seconds with the time.
于 2012-12-16T15:14:10.760 回答
0

试试这个: SELECT NOW() - my_col AS my_diff

于 2012-12-16T15:10:26.347 回答