views:

26

answers:

1

How to get hour from subtract date and time in mysql?

2010-12-04 17:07:14 and 2010-05-30 17:07:19
A: 

I'm assuming you mean you want the # of hours when subtracting the two dates. If that's the case I found the below here: http://www.dbforums.com/mysql/1637603-datediff-hours.html

You can convert both times to seconds using unix_timestamp. Then subtract one from other to get number of seconds between both times. Then divide by 3600 to get the number of hours

 select ( unix_timestamp( "2010-12-04 17:07:14" ) - 
     unix_timestamp("2010-05-30 17:07:19" ) ) / 3600

*Note: This only works for dates after 1970

jon3laze