Php method for determining the number of months between two dates

Source: Internet
Author: User
This article describes how to use php to determine the number of different months between two dates. it involves related techniques related to the php operation date, for more information about how to use php to determine the number of different months between two dates, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:

/*** @ Author injection (injection.mail@gmail.com) * @ var date1 date 1 * @ var date2 date 2 * @ var tags delimiter between year, month, and day, the default value is '-' * @ return the number of months * @ example: $ date1 = ""; $ date2 = ""; $ 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]);}

I hope this article will help you with php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.