Possible Duplicate:
MySQL: how to get the difference between two timestamps in seconds可能重复:MySQL:如何以秒为单位获取两个时间戳之间的差异
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.
如何在两个时间戳之间获得秒(或任何其他单位)的差异?如果我使用选择现在() - '2012-01-01 00:00:00'我得到20110121168303这是错误的。
My favorite solution
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timestampdiff
2 个解决方案
#1
2
UNIX_TIMESTAMP returns an offset number of seconds from epoch. Taking the difference between the two of these is in the unit Seconds.
UNIX_TIMESTAMP返回epoch的偏移秒数。取两者之间的差异在单位秒。
select UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP('2012-01-01 00:00:00')
#2
0
Maybe this can help you : http://forums.mysql.com/read.php?52,124334,124334
也许这可以帮到你:http://forums.mysql.com/read.php?52,124334,124334
#1
2
UNIX_TIMESTAMP returns an offset number of seconds from epoch. Taking the difference between the two of these is in the unit Seconds.
UNIX_TIMESTAMP返回epoch的偏移秒数。取两者之间的差异在单位秒。
select UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP('2012-01-01 00:00:00')
#2
0
Maybe this can help you : http://forums.mysql.com/read.php?52,124334,124334
也许这可以帮到你:http://forums.mysql.com/read.php?52,124334,124334