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

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

WBOY
Release: 2016-06-13 12:37:57
Original
1117 people have browsed it

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 />
Copy after login


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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template