MySQL Timediff Count hours between 10pm to 6am
SELECT
开发者_运维知识库(time_to_sec(
timediff('2011-01-26 23:51:20',
'2011-01-26 15:51:10')
) /60 /60)
AS totalhours
The total hours is 8. What do I have to do so that it only count the hours between 10pm and 6am?
It's definitely simpler if you use:
SELECT hour(timediff('2011-01-26 23:51:20',
'2011-01-26 15:51:10'))
AS totalhours
Use timetosec, other method always gives you a positive result... ie
SELECT
(hour(
timediff('2011-01-29 23:51:20',
'2011-01-26 15:51:10')
) )
AS totalhours
=80
SELECT
(hour(
timediff('2011-01-26 23:51:20',
'2011-01-29 15:51:10')
) )
AS totalhours
= 63
精彩评论