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 > How do I accurately produce the difference between 2 date fields.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-05, 13:17
purpendicular purpendicular is offline
Registered User
 
Join Date: Mar 2004
Location: Rhode Island, USA
Posts: 55
How do I accurately produce the difference between 2 date fields.

how do I create the MySQL code for this example?

eventstart = 2004-01-10 08:15:00 (these time values will be pulled from a record
eventend = 2004-01-12 15:25:00

eventduration = eventend - eventstart

Thanks;
Reply With Quote
  #2 (permalink)  
Old 02-09-05, 19:59
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
select datediff(eventstart,eventend) as eventduration from ...

works in 4.1.1 and up
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-10-05, 11:00
purpendicular purpendicular is offline
Registered User
 
Join Date: Mar 2004
Location: Rhode Island, USA
Posts: 55
How about the ability to calculate the event duration from each record in a table and add it up for a totalduration? Would this be accurate, and how would I go about doing something like this?
Where can I find some good sites or references for queries, I got myself into this and I'm in need of good reference materials.
Thanks;
Reply With Quote
  #4 (permalink)  
Old 02-10-05, 11:06
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
calculating a sum of durations is problematic

one good strategy is to convert each duration to seconds, sum up the seconds, and convert back to a duration (difficult)

best resource for mysql queries is this one
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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