Reputation: 61
I have a database with rows of employee information. In the data I have training dates that expire. I need to compare the expiration date that is pulled to the current date. I'd like to bold and turn red the date if it is within 30 days of expiring. So anytime the page is loaded if it is within that 30 day time frame it will stand out.
This is what I have currently without the if statement I am looking for:
$lic_ex = date("m/d/Y", strtotime($row['lic_ex']));
echo "<td>" . $lic_ex . "</td>";
Upvotes: 1
Views: 38
Reputation: 700
$thirtyDaysLater = (new \DateTime('today'))->modify('+30 day');
$expirationDate= DateTime::createFromFormat('m/d/y' , $input);
$compareDate = (new \DateTime('today'))->modify('+30 day');
if ($compareDate >= $expirationDate) {
echo "<td><strong>" . $lic_ex . "<\strong></td>";
} else {
echo "<td>" . $lic_ex . "</td>";
}
just adjust the createFromFormat parameters to your data
Upvotes: 1