Php 获取第二年的所有日期,间隔不超过周
我需要以两周内的所有天数为例Php 获取第二年的所有日期,间隔不超过周,php,date,Php,Date,我需要以两周内的所有天数为例 2019-01-01 t0 2019-01-14 2019-01-15 to 2019-01-29 2019-01-30 to 2019-02-14 ......................... ......................... ............... 2019-12-xx to 2019-12-31 我需要用php实现它 我不知道如何以这种方式获得一年中的所有天数 你能建议我如何做到这一点吗?是的,你可以在php中找到in
2019-01-01 t0 2019-01-14
2019-01-15 to 2019-01-29
2019-01-30 to 2019-02-14
.........................
.........................
...............
2019-12-xx to 2019-12-31
我需要用php实现它
我不知道如何以这种方式获得一年中的所有天数
你能建议我如何做到这一点吗?是的,你可以在php中找到interval。我已经用数组的形式做了,但是你可以用字符串的形式做。找到我下面的代码
<?php
function dateRange( $first, $last, $step = '+15 day', $format = 'Y/m/d' ) {
$dates = array();
$current = strtotime( $first );
$last = strtotime( $last );
while( $current <= $last ) {
$data = [];
$data['start'] = date( $format, $current );
$current = strtotime( $step, $current );
$data['end'] =date( $format, $current );
$dates[] = $data;
if ($current >= $last) {
break;
}
}
return $dates;
}
echo "<pre>";
print_r( dateRange( '2010/01/01', '2010/05/31') );
什么是数据源?在发布之前,你有没有试过自己解决这个问题?是的,我试过了。只需要用php实现