开发者

How to convert difference between dates into years using php

开发者 https://www.devze.com 2023-01-09 17:47 出处:网络
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.

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

精彩评论

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