开发者

How to convert difference between dates into years using php

I have dates in the format Start and end dates in the format(mm/yyyy). I wan开发者_开发百科t 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.


$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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜