Sometimes, we want to find the number of days between two dates with PHP.
In this article, we’ll look at how to find the number of days between two dates with PHP.
How to find the number of days between two dates with PHP?
To find the number of days between two dates with PHP, we can subtract 2 dates.
For instance, we write
$now = time();
$your_date = strtotime("2021-01-31");
$datediff = $now - $your_date;
echo round($datediff / (60 * 60 * 24));
to subtract the $now
and $your_date
datetime objects to get the days difference.
And then we divide that with 60 * 60 * 24
to get the number of seconds difference between $now
and $your_date
.
Conclusion
To find the number of days between two dates with PHP, we can subtract 2 dates.