How do you work this out

Discussion in 'PHP' started by mumfry, Jul 7, 2010.

  1. #1
    hey yall

    need a little help figuring this out.
    in my database i have a column containing dates saved in this format 2010-05-17 19:31:41
    What i would like to do is select all dates that are, lets say 2 days old to the current date. (eg. 2010-05-17 19:31:41 would be 2010-03-17 19:31:41)
    how can i do this

    thanks
     
    mumfry, Jul 7, 2010 IP
  2. bpasc95

    bpasc95 Active Member

    Messages:
    196
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    70
    #2
    To get a date in the past, you would use PHP's mktime function. Something like this would likely work:
    
    $time_in_past = mktime(0, 0, 0, date("m"), date("d") - 13, date("Y"));
    
    PHP:
    The above will create the corresponding Unix timestamp of 14 days ago.

    -Bing
     
    bpasc95, Jul 7, 2010 IP
  3. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    wow
    awesome dude
    thanx for the help
     
    mumfry, Jul 7, 2010 IP
  4. bpasc95

    bpasc95 Active Member

    Messages:
    196
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    70
    #4
    bpasc95, Jul 7, 2010 IP
  5. linkseo18

    linkseo18 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks it also work for me
     
    linkseo18, Jul 7, 2010 IP
  6. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #6
    You can do it inside your SQL statement;

    select * from your_table where datefield > (now() - INTERVAL 2 day)
    Code (markup):
    No need to mess around with PHP - if you require a different interval, minutes, weeks, seconds, whatever, just change the part after the interval after the line above.
     
    lukeg32, Jul 8, 2010 IP
  7. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #7
    tanx luke
    both ways are very good solution too this problem
     
    mumfry, Jul 10, 2010 IP