Thanks! Here is the code I have. It still doesn't work correctly. THe dates are in the format: "20 January 2011" for example.
$startDate = $_REQUEST['start_day']." ".$_REQUEST['start_month']." ".$_REQUEST['start_year'];
$endDate = $_REQUEST['end_day']." ".$_REQUEST['end_month']." ".$_REQUEST['end_year'];
///begin provided code for date difference
function dateDifference($startDate, $endDate)
{
$startDate = strtotime($startDate);
$endDate = strtotime($endDate);
if ($startDate === false || $startDate < 0 || $endDate === false || $endDate < 0 || $startDate > $endDate)
return false;
$years = date('Y', $endDate) - date('Y', $startDate);
$endMonth = date('m', $endDate);
$startMonth = date('m', $startDate);
// Calculate months
$months = $endMonth - $startMonth;
if ($months <= 0) {
$months += 12;
$years--;
}
if ($years < 0)
return false;
// Calculate the days
$offsets = array();
if ($years > 0)
$offsets[] = $years . (($years == 1) ? ' year' : ' years');
if ($months > 0)
$offsets[] = $months . (($months == 1) ? ' month' : ' months');
$offsets = count($offsets) > 0 ? '+' . implode(' ', $offsets) : 'now';
$days = $endDate - strtotime($offsets, $startDate);
$days = date('z', $days);
return array($years, $months, $days);
}
///end provided code for date difference
$difference = dateDifference($startDate, $endDate);
echo$difference;