Answers for "get no of days between two dates php"

PHP
2

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");
Posted by: Guest on January-14-2021
0

php calculate weeks between two dates

function numWeeks($dateOne, $dateTwo){
    //Create a DateTime object for the first date.
    $firstDate = new DateTime($dateOne);
    //Create a DateTime object for the second date.
    $secondDate = new DateTime($dateTwo);
    //Get the difference between the two dates in days.
    $differenceInDays = $firstDate->diff($secondDate)->days;
    //Divide the days by 7
    $differenceInWeeks = $differenceInDays / 7;
    //Round down with floor and return the difference in weeks.
    return floor($differenceInWeeks);
}

$numOfWeek = numWeeks('2021-01-21', '2021-01-28');
Posted by: Guest on February-24-2021

Code answers related to "get no of days between two dates php"

Browse Popular Code Answers by Language