Log in

View Full Version : MySQL Time Difference BUG



cancer10
02-14-2009, 05:54 AM
Hi

Not sure if this is a bug or not.


I am doing a sql query for time difference using the TIMEDIFF function.

It works for all other but not when not when you are doing a time difference for start time 23:00:00 (11 PM night) and end time 00:30:00 (12 AM Midnight)

if you take a look, the difference is 1.5 hours, but the sql tells me that the difference is 22 hours, 30 minutes



Any solution to this?

Thanx

Twey
02-14-2009, 10:49 AM
No it isn't. 23 - ½ = 22½. Your arithmetic is clearly off, and I suspect you got the arguments the wrong way around — if you'd performed the operation as you describe, you would have got back -22:30:00.

If you meant the times to be on different days then you have to say so, and use TIMESTAMPDIFF (http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timestampdiff)(). Request the difference in seconds, then use SEC_TO_TIME (http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_sec-to-time)() to convert it back into a TIME if it is a TIME you need. However, be aware that this is a truncating operation: any value greater than a day will be truncated, and a warning generated.

If you think it's a bug, it probably isn't. Don't go declaring every surprise a bug — developers generally don't like the implication that you know their software better than they do.