Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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以10次迭代一周递增一个日期_Php - Fatal编程技术网

使用php以10次迭代一周递增一个日期

使用php以10次迭代一周递增一个日期,php,Php,我想将开始日期增加1周10次。此代码不起作用: <?php $start_date = "06/25/2012"; $date = strtotime($start_date); $X=1; while ($X <= 10) {$X++; $Y=7*$X; $date = strtotime("+ $Y days", $date); echo date('m/d/Y', $date)."<br>"; } 这是错误的 您可能正在寻找以下内容: $start\

我想将开始日期增加1周10次。此代码不起作用:

<?php 

$start_date = "06/25/2012";  
$date = strtotime($start_date);
$X=1;

while ($X <= 10) {$X++; $Y=7*$X;

$date = strtotime("+ $Y days", $date);
echo date('m/d/Y', $date)."<br>";

}

这是错误的

您可能正在寻找以下内容:

$start\u date=“2012年6月25日”;
$date=strottime($start\u date);
$X=1;

而($X使用
DateTime
对象:

$date = new DateTime('2012-06-25');
for ($i = 1; $i <= 10; $i++) {
    $date->modify('+1 week');
    echo $date->format('m/d/Y');
}
$date=新日期时间('2012-06-25');
对于($i=1;$i修改(“+1周”);
echo$date->format('m/d/Y');
}

Ideone:

试试这段代码。这将为您提供50次1周周期日期列表

<?php
$date = "05/01/2016";
$weekDates = '';

for ( $i = 1; $i <= 50; $i++ ) {
   $date = date("m/d/Y", strtotime("+1 weeks", strtotime($date)));
   $weekDates .= $date . '<br>';
}

echo $weekDates;

回答:

<?php 

$start_date = "06/25/2012";  
$date = strtotime($start_date);
$newDate = $date;

for ($x = 1; $x<=10; $x++)
{
    $newDate = $newDate + (86400*7);//adding the amount of seconds in a week
    $buffer = date("n/j/Y", $newDate);
    echo "{$buffer}<br>";
}

试试这个
回音日期(“m.d.Y”,strotime(+1周),strotime($start_date))
$Y
改成
7
$date=strotime(+7天),日期));告诉我我的答案是否对你有用。其他答案也都是正确的。但这个答案遵循了我提供的代码。
<?php
$date = "05/01/2016";
$weekDates = '';

for ( $i = 1; $i <= 50; $i++ ) {
   $date = date("m/d/Y", strtotime("+1 weeks", strtotime($date)));
   $weekDates .= $date . '<br>';
}

echo $weekDates;
<?php 

$start_date = "06/25/2012";  
$date = strtotime($start_date);
$newDate = $date;

for ($x = 1; $x<=10; $x++)
{
    $newDate = $newDate + (86400*7);//adding the amount of seconds in a week
    $buffer = date("n/j/Y", $newDate);
    echo "{$buffer}<br>";
}