finding Datetime difference in seconds

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prileep
    New Member
    • Jan 2007
    • 20

    finding Datetime difference in seconds

    Hi,
    I want to find the the exact difference between two dates in seconds through MySQL query.
    Version: 4.1
    Platform: Linux
    Source code:
    >select datediff('2007-01-09 10:24:46','2007-01-09 10:23:46')
    The datediff() function has only two datetime parameters and returns the difference in days.Instead if i want the value to be returned in seconds,what is the possible way??
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Originally posted by prileep
    Hi,
    I want to find the the exact difference between two dates in seconds through MySQL query.
    Version: 4.1
    Platform: Linux
    Source code:
    >select datediff('2007-01-09 10:24:46','2007-01-09 10:23:46')
    The datediff() function has only two datetime parameters and returns the difference in days.Instead if i want the value to be returned in seconds,what is the possible way??
    Use the TIMEDIFF and TIME_TO_SEC functions, as in:
    Code:
    SELECT TIME_TO_SEC(TIMEDIFF('2007-01-09 10:24:46','2007-01-09 10:23:46'));
    Ronald :cool:

    Comment

    • prileep
      New Member
      • Jan 2007
      • 20

      #3
      I am really thankful to u with the solution u given for this. I could achieve this by some other twisted method. But your solution helped me to calculate in subqueries itself,because iwanted to calculate in subquery.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        We learn every day! Come back when you have more questions.

        Ronald :cool:

        Comment

        • preejith
          New Member
          • Nov 2007
          • 3

          #5
          Originally posted by ronverdonk
          Use the TIMEDIFF and TIME_TO_SEC functions, as in:
          Code:
          SELECT TIME_TO_SEC(TIMEDIFF('2007-01-09 10:24:46','2007-01-09 10:23:46'));
          Ronald :cool:
          thank you...... you are great

          Comment

          • morsol
            New Member
            • Jan 2012
            • 1

            #6
            Note that the solution only works when the datetimes are less than 35 days apart!
            TIMEDIFF retuns a TIME datatype, and the max value for TIME is 838:59:59 hours (=34,96 days)

            Comment

            Working...