Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP确定周范围?_Php_Date - Fatal编程技术网

如何使用PHP确定周范围?

如何使用PHP确定周范围?,php,date,Php,Date,我试图用PHP确定星期一到星期天的范围。我能够计算周数,但我无法为每个星期获得正确的结束周范围 以下是我到目前为止的情况: $start_date = 1337621424; $end_date = 1349964545; $start_week = (int)date('W', $start_date); $end_week = (int)date('W', $end_date); echo "START WEEK: " . $start_week . "<BR>"; ec

我试图用PHP确定星期一到星期天的范围。我能够计算周数,但我无法为每个星期获得正确的结束周范围

以下是我到目前为止的情况:

$start_date = 1337621424;
$end_date = 1349964545;

$start_week = (int)date('W', $start_date); 
$end_week = (int)date('W', $end_date); 

echo "START WEEK: " . $start_week . "<BR>";
echo "END WEEK: " . $end_week . "<BR>";

$dates = array();

if ($start_week && $end_week) {

    for ($week=$start_week; $week<=$end_week; $week++) {
        echo "WEEK: " . $week . "<BR>";

        $startdate = strtotime ( '- ' . $week. ' week', strtotime ( date('Y-m-d') ) ) ;
        $startdate = date ( 'Y-m-d' , $startdate );

        //$end = date('Y-m-d');
        $end = strtotime ( '- ' . ($week + 1) . ' week', strtotime ( $startdate ) ) ;
        $end = date ( 'Y-m-d' , $end );

        $dates[$week]['start'] = $startdate;
        $dates[$week]['end'] = $end;
    }

    print_r($dates);
}   
$start\u date=1337621424;
$end_date=1349964545;
$start_week=(int)日期('W',$start_date);
$end_week=(int)日期('W',$end_date);
回声“开始周:”$开始一周。“
”; 回声“周末:”$周末。“
”; $dates=array(); 如果($start_week&$end_week){ 对于($week=$start\u week;$week您可以尝试

$startDate = new DateTime();
$startDate->setTimestamp(1337621424);

$endDate = new DateTime();
$endDate->setTimestamp(1349964545);

$dates = array();
while ( $startDate <= $endDate ) {
    $week = array();
    $week['start'] = $startDate->format("Y-m-d");
    $startDate->modify("+1 week");
    $week['end'] = $startDate->format("Y-m-d");

    $dates[$startDate->format("W")] = $week ;
}
var_dump($dates);
$startDate=new DateTime();
$startDate->setTimestamp(1337621424);
$endDate=新的日期时间();
$endDate->setTimestamp(1349964545);
$dates=array();
而($startDate格式(“Y-m-d”);
$startDate->modify(“+1周”);
$week['end']=$startDate->格式(“Y-m-d”);
$dates[$startDate->format(“W”)]=$week;
}
var_dump(日期);
您正在从开始日期开始操作
($week+1)周。