开发者

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

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

开发者_C百科2010-12-04 17:07:14 and 2010-05-30 17:07:19


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜