Get the number of days between two dates in PHP
$startDate = new DateTime("2019-10-27");
$endDate = new DateTime("2020-04-11");
$difference = $endDate->diff($startDate);
echo $difference->format("%a");
Get the number of days between two dates in PHP
$startDate = new DateTime("2019-10-27");
$endDate = new DateTime("2020-04-11");
$difference = $endDate->diff($startDate);
echo $difference->format("%a");
php date difference in days
<?php
/**
* array _date_diff(string)
* function to get the difference between the date you enter and today, in days, months, or years.
* @param string $mydate
* @return array
*/
function _date_diff($mydate) {
$now = time();
$mytime = strtotime(str_replace("/", "-", $mydate)); // replace '/' with '-'; to fit with 'strtotime'
$diff = $now - $mytime;
$ret_diff = [
'days' => round($diff / (60 * 60 * 24)),
'months' => round($diff / (60 * 60 * 24 * 30)),
'years' => round($diff / (60 * 60 * 24 * 30 * 365))
];
return $ret_diff;
}
// example:
var_dump(_date_diff('2021-09-11'));
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us