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

PHP Get the middle month between two months

不言
不言Original
2018-04-09 17:45:471667browse

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);



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!

Statement:
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