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
精彩评论