开发者

MySQL: Get the difference between timestamps [duplicate]

This question already has answers here: Closed 12 years ago. 开发者_StackOverflow中文版

Possible Duplicate:

MySQL: how to get the difference between two timestamps in seconds

How can I get the difference in seconds (or any other unit) between two timestamps? If I use select NOW() - '2012-01-01 00:00:00' I get 20110121168303 which is wrong.

My favorite solution

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timestampdiff


UNIX_TIMESTAMP returns an offset number of seconds from epoch. Taking the difference between the two of these is in the unit Seconds.

select UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP('2012-01-01 00:00:00')


Maybe this can help you : http://forums.mysql.com/read.php?52,124334,124334

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜