Need help on find row with is 30 days old

Discussion in 'PHP' started by urber, Dec 25, 2007.

  1. #1
    Hello PHP experts,

    please help me with this...

    I need to pull out data in mysql database for the row which are 30 days old.

    My table name is "check"

    Column

    id name time
    1 simon 2007-12-25 15:53:18
    2 Jen 2007-12-25 15:53:18
    3 Kenny 2007-11-14 15:53:18
    4 Peter 2007-11-04 15:53:18
    5 Ronny 2007-12-07 15:53:18

    As you can see in this table there are 2 row which are 30 days and they are ID 3 and 4.

    How can I check and pull out this data and echo it on the page?


    Please kindly help with code thanks.
     
    urber, Dec 25, 2007 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    in what format you are storing date and time in the sql table

    Are u posting the view of sql table

    Regards

    Alex
     
    kmap, Dec 25, 2007 IP
  3. urber

    urber Active Member

    Messages:
    239
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Hi,

    I am storing the the date and time as "now()". the structure format for this "time" column is timestamp

    Ya thats how my sql table looks like.

    For the echo part I am ok, just need the checking part... something like this..



    $query = "SELECT id, name, time FROM check";
    $strSQL = mysql_query($query);

    while($row = mysql_fetch_array($strSQL)) {

    if($row['time'] ???? how to do this part??) {
    echo "$row['name'] is 30 days old<br>";
    } else {
    echo "Nothing to display";
    }
    }




    Thanks
     
    urber, Dec 25, 2007 IP
  4. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #4
    try this

    SELECT * FROM Table WHERE DateDiff('d', time, now()) < 7

    Regards

    Alex
     
    kmap, Dec 25, 2007 IP
  5. urber

    urber Active Member

    Messages:
    239
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Hi thanks for helping but it not displaying any results.
     
    urber, Dec 25, 2007 IP
  6. dataman

    dataman Peon

    Messages:
    94
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Something like...

    SELECT id, name, time FROM check WHERE time < DATE_SUB(NOW(), INTERVAL + 30 DAY) ORDER BY time ASC;
    Code (markup):
     
    dataman, Dec 25, 2007 IP
  7. faceless

    faceless Peon

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    WHERE TO_DAYS(time) < (TO_DAYS(NOW()) - 30) should return all entries older than 30 days.
     
    faceless, Dec 25, 2007 IP