Thursday, 2 May 2013

Increment date using while loop in php



 $start_date = "2013-01-01";
  $end_date = "2013-01-20";
  $next_date = $start_date;

  while(strtotime($next_date) <= strtotime($end_date))
  {
    echo "$next_date
";
    $next_date = date ("Y-m-d", strtotime("+5 day", strtotime($next_date)));
  }


Ok in for loop?


$start_date = "2013-01-01";
$end_date = "2013-01-25";
$next_date = $start_date;

for($i=0;$i<=(strtotime($next_date) <= strtotime($end_date));$i++)
{
echo "$next_date
";
$next_date = date ("Y-m-d", strtotime("+2 day", strtotime($next_date)));
}





No comments:

Post a comment