2

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

Community
  • 1
  • 1
700 Software
  • 81,209
  • 77
  • 221
  • 333

2 Answers2

2

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')
RichardTheKiwi
  • 102,799
  • 24
  • 193
  • 261
0

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

Eray
  • 6,897
  • 15
  • 65
  • 118