If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySQL Time Difference BUG

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-14-09, 00:55
cancer10 cancer10 is offline
Registered User
 
Join Date: Mar 2008
Posts: 33
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
__________________
Interview Questions & Answers - www.focusinterview.com
http://outlineme.com/cancer10
Reply With Quote
  #2 (permalink)  
Old 02-14-09, 05:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by cancer10
Not sure if this is a bug or not.
i bet it isn't
Code:
CREATE TABLE test_timediff
( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT
, start_datetime DATETIME
, end_datetime DATETIME
);
INSERT INTO test_timediff VALUES
 ( 1, '2009-02-13 23:00:00','2009-02-13 00:30:00' )
,( 2, '2009-02-14 23:00:00','2009-02-13 00:30:00' )
,( 3, '2009-02-13 23:00:00','2009-02-14 00:30:00' )
;
SELECT t.*
     , TIMEDIFF(start_datetime,end_datetime) AS diff1
     , TIMEDIFF(end_datetime,start_datetime) AS diff2
  FROM test_timediff AS t
;
/* results:
id start_datetime      end_datetime          diff1     diff2
 1 2009-02-13 23:00:00 2009-02-13 00:30:00  22:30:00 -22:30:00
 2 2009-02-14 23:00:00 2009-02-13 00:30:00  46:30:00 -46:30:00
 3 2009-02-13 23:00:00 2009-02-14 00:30:00 -01:30:00  01:30:00
*/
any questions?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-14-09, 05:39
cancer10 cancer10 is offline
Registered User
 
Join Date: Mar 2008
Posts: 33
This is now resolved.


Thanx
__________________
Interview Questions & Answers - www.focusinterview.com
http://outlineme.com/cancer10
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On