difference between two dates

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew

    #1

    difference between two dates

    1) I have mySQL 3.23 installed. I have a record with two date/times
    fields in YYYY-MM-DD HH:MM:SS format. How do I find the difference
    between those two date/times? (I would also like to know it with
    seconds left off.)

    2) Let's say I have two records each with a date/time field in
    YYYY-MM-DD HH:MM:SS format. How do I find the difference in date/times
    when each field is in a different record?

    Thanks,
    -Andrew K
  • Bill Karwin

    #2
    Re: difference between two dates

    Andrew wrote:[color=blue]
    > 1) I have mySQL 3.23 installed. I have a record with two date/times
    > fields in YYYY-MM-DD HH:MM:SS format. How do I find the difference
    > between those two date/times? (I would also like to know it with
    > seconds left off.)[/color]

    Unfortunately, the DATEDIFF() function is only available in MySQL 4.1.1.
    In my project using MySQL 3.23, I used TO_DAYS(date1) - TO_DAYS(date2).

    In my case, rounding to the nearest day was appropriate. You might want
    to use the TIME_TO_SEC() function to get the difference between the two
    datetime values, in addition to the expression I mention above. I'll
    leave the application of that function up to you.
    [color=blue]
    > 2) Let's say I have two records each with a date/time field in
    > YYYY-MM-DD HH:MM:SS format. How do I find the difference in date/times
    > when each field is in a different record?[/color]

    Join the table to itself to get values from different records into one
    SQL expression.

    Regards,
    Bill K.

    Comment

    Working...