How to get year month day difference between two dates using php

There are a simple way to get the number of year month and day between two dates in PHP. Using the formula, you can easily count year month and day between two dates in PHP. You may also like Two date get hour and minute using php and Get total minute and second difference between two dates using php.

Code

$StartDate='2010-02-20';
$EndDate='2011-12-01';
$diff   = abs(strtotime($StartDate) - strtotime($EndDate));
echo 'years = '.$years  = floor($diff / (365*60*60*24));
echo "<br>";
echo 'months = '.$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
echo "<br>";
echo  'days = '.$days   = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

Leave a Reply

Your email address will not be published. Required fields are marked *