SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2001
    Location
    Portland, OR
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL: date arithmetic

    Hi, for some reason I think this is really simple but I just can't get it. I have a table with a datetime column. I want to find the number of days between now() and the field value. For example:

    select now() - datetimecol from thetable where id=...

    and I get a number back. not sure what that is but how do I get the number of days between now() and datetimecol's value?

    thanks much
    Discogs - Building the definitive electronic music database...

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this
    Code:
    SELECT TO_DAYS(NOW()) - TO_DAYS(other_date) FROM your_table;
    Paul

  3. #3
    SitePoint Member
    Join Date
    Jan 2001
    Location
    Portland, OR
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahhhh, that works. exactly what I'm looking for. thank you!
    Discogs - Building the definitive electronic music database...


Bookmarks

Posting Permissions

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