If I do a query such as the following:
SELECT HOUR( TIMEDIFF('2012-08-12 02:25:00',
'2012-09-14 02:25:33') ) as result
the result is 792, even though I'm subtracting a past data from a future date.
If I remove HOUR()
and do:
SELECT TIMEDIFF('2012-08-12 02:25:00',
'2012-09-14 02:25:33') as result
Then the value is -792:00:33
. Therefore clearly HOUR()
is converting -792 to 792. I've tried it with other dates and result is the same (always positive hour being returned).
The manual doesn't say anything about this behaviour.
Is this a bug, or is it a feature that I can rely on to be present on all recent mysql installations?
There's a way to get the positive hour and the negative hour. EXTRACT
will get the negative one.
SELECT EXTRACT(HOUR FROM '-01:00:00'), HOUR('-01:00:00')
Will return:
-1 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With