Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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 "
";
// Total amount of days
echo $intvl->days . " days ";

//output: 1 year, 2 months and 1 day
//        428 days
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #Use #Objects #PHP #Above #Calculate #Difference #Between #Two #Dates #Using #PHP
ADD COMMENT
Topic
Name
1+3 =