Home > php教程 > PHP源码 > 判断两个日期之间相差多少个月份的函数

判断两个日期之间相差多少个月份的函数

PHP中文网
Release: 2016-05-25 17:15:28
Original
1472 people have browsed it

1. [代码][PHP]代码   

/**
 * @author injection(injection.mail@gmail.com)
* @final 2006-09-23
* @var date1日期1
* @var date2 日期2
* @var tags 年月日之间的分隔符标记,默认为'-' 
* @return 相差的月份数量
* @example:
$date1 = "2003-08-11";
$date2 = "2008-11-06";
$monthNum = getMonthNum( $date1 , $date2 );
echo $monthNum;
*/

function getMonthNum( $date1, $date2, $tags='-' ){
  $date1 = explode($tags,$date1);
  $date2 = explode($tags,$date2);
  return abs($date1[0] - $date2[0]) * 12 + abs($date1[1] - $date2[1]);
 }
Copy after login

                   

                   

Related labels:
php
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
Latest Articles by Author
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template