Home > Article > Backend Development > PHP method to determine the number of months difference between two dates code example
This article mainly introduces the method of php to determine the number of months between two dates. It involves related skills of operating dates in PHP. Friends in need can refer to this article
The example describes how PHP determines the number of months between two dates. Share it with everyone for your reference. The specific implementation method is as follows:
/** * @author injection(injection.mail@gmail.com) * @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]); }
The above is the detailed content of PHP method to determine the number of months difference between two dates code example. For more information, please follow other related articles on the PHP Chinese website!