SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    936
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    distance from current dates

    The table has dates ranging from the past to the future.
    How would I figure out the distance from the current date so that the result from 3 days in the future and 3 days in the past were the same?

    Thank you E

  2. #2
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    936
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I figured it out:
    Code MySQL:
    SELECT member_id, end_date,  
    IF((end_date-now())<0, (end_date-now())*-1, end_date-now()) AS 'deviation'
    FROM `response` 
    WHERE `status` ='yes' and end_date >'0'
    GROUP BY `member_id`

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    SELECT member_id, end_date,
    GREATEST(end_date,NOW()) - LEAST(end_date,NOW()) AS 'deviation'
    FROM ...

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •