If I have
$time_interval = date_diff(date1, date2)
How can I do this in PHP?
If ($time_interval >= ('2 months and 15 days'))
echo "time is '2 months and 15 days' or more"
else
echo "time is less than '2 months and 15 days'"
I tried
if ($time_interval->m <= 2 and $time_interval->d < 15)
But this will return FALSE
for 1 month and 20 days
which is obviously wrong
Is there something like..?
$time_lapse = create_my_own_time_lapse(2months & 15 days)
Then it would be very neat to compare both
If ($time_interval >= $time_lapse)
SOLUTION
date_diff
retuns a DateInterval
object. I found the way to create my own DateInterval
for '2 months and 15 days'. This is my updated code:
Visit PHP DateInterval manual for details
$today = new DateTime(date('Y-m-d'));
$another_day = new DateTime("2019-05-10");
$time_diff = date_diff($today, $another_day);
// 'P2M15D' is the interval_spec for '2 months and 15 days'
$time_interval = new DateInterval('P2M15D');
// Let's see our objects
print_r($time_diff);
print_r($timeInterval);
if($time_diff >= $time_interval)
echo "<br/>time is '2 months and 15 days' or more";
else
echo "<br/>time is less than '2 months and 15 days'";