Avatar of Sim1980
 asked on

How to figure out if a date is within 30 days in php

Hi all.

I have a php script that displays records in a table. I want to be able to show specific records in yellow when the field: InsuranceExpiration is within 30 days of expiration.

What is the correct php syntax to figure out when a date (i.e. InsuranceExpiration) is within 30 days?

Thank you in advance!

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Ray Paseur

This answer (and much more) about date and time is shown in this article.  PHP date() and strtotime() play together in ways that are almost magical.  To use them correctly keep all of your internal date/time representations in ISO-8601 format.

Be aware that PHP and MySQL keep the date and time separately.  You may want to verify how close or far apart the servers are.

$future = date('c', strtotime('TODAY + 30 DAYS'));
if ($insuranceExpiration < $future) $displayStyle .= ' yellow';
// etc... 

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck