PHP 获取两个月之间的中间月
程序员文章站
2024-01-28 11:59:22
...
开始日期要与结束日期相差一个月以上:
$time1 = strtotime('2014-10-04'); //开始日期
$time2 = strtotime('2015-02-06'); //结束日期
$month = array(); //定义数组
$month[] = date('Y-m',$time1);
while( ($time1 = strtotime('+1 month', $time1)) <= $time2){
$month[] = date('Y-m',$time1); // 取得递增月;
}
print_r($month);
获取两个月直接的所有月是上面的升级版
$time1 = strtotime(date('Y-m-01',strtotime('2018-05-26'))); //开始日期
$time2 = strtotime(date('Y-m-01',strtotime('2018-06-06'))); //结束日期
$month = array(); //定义数组
$month[] = date('Y-m',$time1);
while( ($time1 = strtotime('+1 month', $time1)) <= $time2){
$month[] = date('Y-m',$time1); // 取得递增月;
}
print_r($month);
上一篇: 15-知识笔记(java_for循环)
下一篇: django 自定义过滤器的实现