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");
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");
how to calculate days between two dates in php
<?php
function dateDifference($start_date, $end_date)
{
// calulating the difference in timestamps
$diff = strtotime($start_date) - strtotime($end_date);
// 1 day = 24 hours
// 24 * 60 * 60 = 86400 seconds
return ceil(abs($diff / 86400));
}
// start date
$start_date = "2016-01-02";
// end date
$end_date = "2016-01-21";
// call dateDifference() function to find the number of days between two dates
$dateDiff = dateDifference($start_date, $end_date);
echo "Difference between two dates: " . $dateDiff . " Days ";
?>
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us