Jump to content


Photo

time difference between 2 time stamps


  • Please log in to reply
1 reply to this topic

#1 Space Cowboy

Space Cowboy
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 25 March 2006 - 07:59 PM

Hi,im looking for a simple bit of code that will get me the difference in MINUTES between 2 time stamps.
The time/date stamps in the database are in this format

20060324003725

Cheers!

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 25 March 2006 - 10:13 PM

You didn't mention what version of MySQL you're using (or even if that's what you're using).

Anyway, you should be able to simply subtract one TS column from the other and multiply by 60 to give you the minutes you want.

An alternative is to use the UNIX_TIMESTAMP() function:

SELECT UNIX_TIMESTAMP(date1_column) - UNIX_TIMESTAMP(date2_column) * 60 AS diff_in_minutes FROM table_name

See this for more info:

[a href=\"http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#id3206258\" target=\"_blank\"]http://dev.mysql.com/doc/refman/4.1/en/dat....html#id3206258[/a]









0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users