Home > Backend Development > PHP Tutorial > PHP Get the middle month between two months

PHP Get the middle month between two months

不言
Release: 2023-03-23 12:56:01
Original
1656 people have browsed it

The content of this article is to share with you PHP to obtain the intermediate month code between two months. Friends in need can refer to it


        $time1 = strtotime('2014-10-04'); //开始日期

        $time2 = strtotime('2015-02-06'); //结束日期

        $month = array(); //定义数组

        $month[] = date('Y-m',$time1);

        while( ($time1 = strtotime(&#39;+1 month&#39;, $time1)) <= $time2){

            $month[] = date(&#39;Y-m&#39;,$time1); // 取得递增月;
        }

        print_r($month);
Copy after login



The above is the detailed content of PHP Get the middle month between two months. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template