Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2004
    Posts
    4

    Unanswered: Help with date functions

    Hi every one

    I need help with the date function

    I want to subtract two dates with type DATETIME to know how much time user spent.

    will really appriciate it

    regards
    Yasir

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select TO_DAYS(date1) - TO_DAYS(date2)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2004
    Posts
    4
    but that will give me no. of days not time I'm using datetime as type

    regards

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    [Edit]: oops

    select UNIX_TIMESTAMP(datetime1) - UNIX_TIMESTAMP(datetime2)

    this will give you the difference in seconds

    if the difference is less than 24 hours, you can then use SEC_TO_TIME to convert the result back to hh:mm:ss format

    if it's more than 24 hours, you have to do additional arithmetic
    Last edited by r937; 06-11-04 at 10:21.
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jun 2004
    Posts
    4

    Smile

    Thanks man really appriciate it.
    caio

Posting Permissions

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