Answers for "day difference between two dates in 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
1

Calculate the Difference Between Two Dates Using PHP

$firstDate = "2019-01-01";
$secondDate = "2020-03-04";

$dateDifference = abs(strtotime($secondDate) - strtotime($firstDate));

$years  = floor($dateDifference / (365 * 60 * 60 * 24));
$months = floor(($dateDifference - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
$days   = floor(($dateDifference - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 *24) / (60 * 60 * 24));

echo $years." year,  ".$months." months and ".$days." days";

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

how to calculate days difference between two dates in php

// how to calculate days difference between two dates in laravel

use DateTime; // inside Controller Class

$startDate = new DateTime($request->start_date);
$endDate   = new DateTime($request->end_date);

$daysDifference = ($startDate->diff($endDate)->days);
Posted by: Guest on March-05-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 "day difference between two dates in php"

Browse Popular Code Answers by Language