How to calculate difference between two dates?
Someday, sometimes, you might need to Calculate difference between two dates. No need to bite your teeth and wander on the web! Here are some ways you can easily get the difference between any two dates. Let’s take two random dates.. Start Date: 2010-03-24 and End Date: 2015-06-26 Use simple DateTime and DateInterval objects;
1 2 3 4 5 6 7 8 9 | $date1 = new DateTime('2010-03-24'); $date2 = new DateTime('2015-06-26'); $difference = $date1->diff($date2); //To render in years, months and days echo "The difference is: " . $difference->y . " years " . $difference->m . " months and " . $difference->d . " days."; //To render only the number of days between the two dates echo "The difference is: " . $difference->days . " days." |
…