Results 1 to 2 of 2

Thread: MySQL Time Difference BUG

  1. #1
    Join Date
    Dec 2007
    Posts
    123
    Thanks
    17
    Thanked 1 Time in 1 Post

    Question MySQL Time Difference BUG

    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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(). Request the difference in seconds, then use 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.
    Last edited by Twey; 02-14-2009 at 11:01 AM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •