Hello friends,
I have two date 2016-04-04 and 2016-08-31 and now I want to display its difference as 4 months 24 days format. I have created a function to return date difference in year, months and days format
$date1 = '2016-08-31';
$date2 = '2016-04-04';
//Calling function to get date difference in year, month and days format
$dataDifference = getDateDifference($date1, $date2)
echo "Year : ".$dataDifference['years'];
echo "Month : ".$dataDifference['months'];
echo "Days : ".$dataDifference['days'];
/*
* Get date difference
* @Param 1 : from date
* @Param 2 : to date
* @Return : array of date difference
*/
function getDateDifference($date1, $date2){
$data = array();
$diff = abs(strtotime($date2) - strtotime($date1));
$data['years'] = floor($diff / (365*60*60*24));
$data['months'] = floor(($diff - $data['years'] * 365*60*60*24) / (30*60*60*24));
$data['days'] = floor(($diff - $data['years'] * 365*60*60*24 - $data['months']*30*60*60*24)/ (60*60*24));
return $data;
}
0 Comment(s)