Answers for "difference 2 weeks php"

PHP
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 "difference 2 weeks php"

Browse Popular Code Answers by Language