Answers for "Use DateTime() and DateInterval() Objects for PHP 5.3 and Above and Calculate the Difference Between Two Dates Using PHP"

0

Use DateTime() and DateInterval() Objects for PHP 5.3 and Above and Calculate the Difference Between Two Dates Using PHP

phpCopy$firstDate  = new DateTime("2019-01-01");
$secondDate = new DateTime("2020-03-04");
$intvl = $firstDate->diff($secondDate);

echo $intvl->y . " year, " . $intvl->m." months and ".$intvl->d." day"; 
echo "\n";
// Total amount of days
echo $intvl->days . " days ";

//output: 1 year, 2 months and 1 day
//        428 days
Posted by: Guest on April-23-2021

Code answers related to "Use DateTime() and DateInterval() Objects for PHP 5.3 and Above and Calculate the Difference Between Two Dates Using PHP"

Browse Popular Code Answers by Language