Are you want to calculate the difference between two dates in PHP? There are a simple way to get the number of days between two dates in PHP. Using the date_diff()
function, you can easily count days between two dates in PHP.
The following script calculates the difference between two dates using PHP and shows the days count.
<?php
$date1 = date_create("2017-04-15");
$date2 = date_create("2017-05-18");
//difference between two dates
$diff = date_diff($date1,$date2);
//count days
echo 'Days Count - '.$diff->format("%a");
?>
Two PHP functions are used in the above script to get the number of days between two dates.
Thanks!
For dyanamically calculating the days gap, this code can be used:
format(“%a”);
very helpful code for me 🙂
This code is helpful, but i need to take two dates dynamically and then calculate the remaining days
Nice code indeed
thanks for great code