Jump to content

increment date in while loop


tiota

Recommended Posts

PHP vesion 5.3.0

Hi, Can anyone help me out with this code. I want to print out

dates from $start_date up to $end_date but it only returns

"2010-07-02"

 

<?php

  $i=1;

  $start_date = "2010-07-01";

  $end_date = "2010-07-31";

  $next_date = $start_date;

 

  while($next_date <= $end_date)

  {

 

    $next_date = strtotime("+$i day", strtotime($start_date));

    echo date("Y-m-d",$next_date);

    echo "<br>";

    $i++;

 

}

 

 

?>

 

Thanks in advance.

 

 

Link to comment
https://forums.phpfreaks.com/topic/207788-increment-date-in-while-loop/
Share on other sites

  • 2 years later...
<?php

  date_default_timezone_set('UTC');

  $start_date = "2012-10-01";

  $end_date = "2012-12-31";

  $next_date = $start_date;

 

  while(strtotime($next_date) <= strtotime($end_date))

  {

    echo "$next_date<br>";

    $next_date = date ("Y-m-d", strtotime("+1 day", strtotime($next_date)));

  }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.