Hi,
I need to subtract one date from another, giving the result in months. However, the following code does not seem to give the correct answer:
// ----------------- subtract dates and find difference in months --------------------
list ($year1, $month1, $day1) = explode ("-", $min_date);
list ($year2, $month2, $day2) = explode ("-", $max_date);
$timestamp1 = mktime(0,0,0, $month1, $day1, $year1);
$timestamp2 = mktime(0,0,0, $month2, $day2, $year2);
$diff = ($timestamp1 > $timestamp2) ? ($timestamp1 - $timestamp2) : ($timestamp2 - $timestamp1);
$years_diff = date("Y", $diff) - 1970;
if ($years_diff > 0){
$yearstomonths = $years_diff / 12;
}else{
$yearstomonths = 0;
}
$numberofmonths = $yearstomonths + date("m", $diff)-1;
Could someone please advise me where I'm going wrong?
cheers, Graham