0

Good Morning,

I am trying to run a mysql query to see if the field 'Date' is within 7 days of the current date or not. If it is less than 7 days old, I want to echo an image called current.jpg. If it is more than 7 days old, I want to echo an image called notcurrent.jpg. I have been close but still cant seem to get it....Any help would be appreciated.

     <?php

    $Now = time(); 
    $Lastweek = time() - (7 * 24 * 60 * 60);



    if($row['Date']<= $Lastweek) {
    echo "<img src='/images/current.jpg' width='80' height='75'><br>";
    } else if ($row['Date'] > $Lastweek) {
    echo "<img src='/images/notcurrent.jpg' width='80' height='75'><br>";
    }

    ?>
2
Contributors
2
Replies
15
Views
2 Years
Discussion Span
Last Post by diafol
0

I got it to work...

if (strtotime($row['Date']) >= strtotime('-7 days')) {
echo "<img src='/images/current.jpg' width='80' height='75'><br>";
} else {
echo "<img src='/images/notcurrent.jpg' width='80' height='75'><br>";
}
0

Just a point. strtotime relative dates is far better than using "seconds calculations" as they take into account daylight saving and leap years.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.