Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    55

    Unanswered: 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;

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select datediff(eventstart,eventend) as eventduration from ...

    works in 4.1.1 and up
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2004
    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;

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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