Answers for "how to find time interval betweeen 2 dates in php"

PHP
2

php get date between two dates

$period = new DatePeriod(
     new DateTime('2010-10-01'),
     new DateInterval('P1D'),
     new DateTime('2010-10-05')
);

//Which should get you an array with DateTime objects. 

//To iterate

foreach ($period as $key => $value) {
    //$value->format('Y-m-d')       
}
Posted by: Guest on August-22-2020
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 "how to find time interval betweeen 2 dates in php"

Browse Popular Code Answers by Language