Answers for "php get diff in days"

PHP
1

php get day diff

$now = time(); // or your date as well
$your_date = strtotime("2010-01-31");
$datediff = $now - $your_date;

echo round($datediff / (60 * 60 * 24));
Posted by: Guest on April-22-2020
2

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'));
Posted by: Guest on September-24-2021

Browse Popular Code Answers by Language