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>";
    }

    ?>

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>";
}
Member Avatar for diafol

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.