I am working out the months, days, hours and minutes between two dates, I have successfully got it to work out the months, days and minutes, but I cannot for the life of get it to work out the minutes, below is my code.
<?php
$date1 = "2012-07-01 00:00:00";
$date2 = "2012-09-30 00:00:00";
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$minutes = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24) / (60*60*24) / (60*60));
printf("%d years, %d months, %d days, %d minutes\n", $years, $months, $days, $minutes);
?>
The best and most accurate way to approach this problem is to use the
DateTimeclass. Otherwise you’ll run into issues when you deal with anomalies in dates (leap year, etc).This outputs: