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
  • 85,281
  • 83
  • 234
  • 341

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
  • 105,798
  • 26
  • 196
  • 262
0

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

Eray
  • 7,038
  • 16
  • 70
  • 120