Home >Backend Development >PHP Tutorial > PHP怎的计算两个日期相差几个月

PHP怎的计算两个日期相差几个月

WBOY
WBOYOriginal
2016-06-13 12:37:571116browse

PHP怎样计算两个日期相差几个月?

<br />
<?php<br />
function getMonthNum( $date1, $date2, $tags='-' ){<br />
  $date1 = explode($tags,$date1);<br />
  $date2 = explode($tags,$date2);<br />
  return abs($date1[0] - $date2[0]) * 12 + abs($date1[1] - $date2[1]);<br />
 }<br />
<br />
echo getMonthNum("2013-02-01","2014-01-01",'-');<br />
<br />
?><br />


以上代码计算出相差13个月,不知道该怎么改才能正常一些?

php date
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn