views:

50

answers:

2

Hi,

I have dates in the format Start and end dates in the format(mm/yyyy). I want to display the difference of the dates in years, months.

example:

start date 09/2008
end date 07/2010

display should read

1 Year, 10 months.

I appreciate any help.

Thanks.

+6  A: 
$start = DateTime::createFromFormat('m/Y', '09/2008');
$end = DateTime::createFromFormat('m/Y', '07/2010');
$diff = $start->diff($end);
echo $diff->format('%y years, %m months');

Note that this requires PHP 5.3.0 or higher.

Daniel Egeberg
A: 

Bookmark this page on the php website: http://php.net/manual/en/function.date.php. Very useful, will allow you to format dates however you want.

Nick