欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php获取两个日期间之间的月份

程序员文章站 2024-01-16 15:06:34
...

提供一个开始日期和结束日期获取这期间的月份 $start_date = '2014-09-08';$end_date = '2015-10-09';$start_arr = explode("-", $start_date);$end_arr = explode("-", $end_date);$start_year = intval($start_arr[0]);$start_month = intval($start_arr[1

提供一个开始日期和结束日期获取这期间的月份

$start_date = '2014-09-08';
$end_date = '2015-10-09';

$start_arr = explode("-", $start_date);
$end_arr = explode("-", $end_date);

$start_year = intval($start_arr[0]);
$start_month = intval($start_arr[1]);

$end_year = intval($end_arr[0]);
$end_month = intval($end_arr[1]);

$diff_year = $end_year-$start_year;

$month_arr = [];
//获取月份
if($diff_year == 0){
	for($month = $start_month;$month";
print_r($month_arr);

Array
(
    [0] => 2014-9-1
    [1] => 2014-10-1
    [2] => 2014-11-1
    [3] => 2014-12-1
    [4] => 2015-1-1
    [5] => 2015-2-1
    [6] => 2015-3-1
    [7] => 2015-4-1
    [8] => 2015-5-1
    [9] => 2015-6-1
    [10] => 2015-7-1
    [11] => 2015-8-1
    [12] => 2015-9-1
    [13] => 2015-10-1
)