Show if Date between 7 and 30 days ago

I am just trying to add some text ‘New’ if a record is less than 7 days old, and ‘Recent’ if it is between 7 and 30 days old.

I have:

<?php
if( strtotime($row_rsNews['(date_updated']) > strtotime('-7 day')) {
echo '<span class="newupdate">NEW</span>';
}
?>

Which works for 7 days.

But what would the syntax be to show RECENT if its between 7 and 30 days?

Trying a few things and this looks like it might be it:

<?php
if( strtotime($row_WADAlodgelikes['MAX(date_updated)']) < strtotime('-7 day') AND      strtotime($row_WADAlodgelikes['MAX(date_updated)']) > strtotime('-30 day')) {
echo '<span class="recentupdate">RECENT</span>';
}
?>

You could do something like this using DateTime →

<?php
$timezone = "America/Detroit"; 
$today = new DateTime("Now", new DateTimeZone($timezone));


$myVar = "2015-04-19";
$dateCheck = new DateTime($myVar, new DateTimeZone($timezone));

/* Get the difference between today and the variable you are checking */
$diff = $today->diff($dateCheck);

// echo '<pre>' . print_r($days, 1) . '</pre>'; // This will give you the options you can do with the object:

if ( $diff->days >= 7 && $diff->days <= 30 ) {
    echo "Display " . $dateCheck->format("F j, Y") . " because it's between 7 days and 30 days ago";
}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.