If I have two variables $startDate="YYYYmmdd"
and $endDate="YYYYmmdd"
, how can I get the number of days between them please?
Thank you.
If you are using PHP 5.3, you can use the new DateTime
class:
$startDate = new DateTime("20101013");
$endDate = new DateTime("20101225");
$interval = $startDate->diff($endDate);
echo $interval->days . " until Christmas"; // echos 73 days until Christmas
If not, you will need to use strtotime
:
$startDate = strtotime("20101013");
$endDate = strtotime("20101225");
$interval = $endDate - $startDate;
$days = floor($interval / (60 * 60 * 24));
echo $days . " until Christmas"; // echos 73 days until Christmas