-1

I wrote a piece of code using date function mktime() in PHP:

mktime(0,0,0,date("m"),date("d"),date("y"))

I got the desired result, but I want next five consecutive dates using for loop.

What would we be the best way of going about this?

user229044
  • 232,980
  • 40
  • 330
  • 338
  • in what form do you have your "next five dates"; what means "next" here? –  Jul 01 '12 at 05:09
  • 1
    "what should I do?" How about [using the search function before asking](http://stackoverflow.com/questions/ask-advice) because this is a duplicate. – Gordon Jul 01 '12 at 06:58
  • @SparKot Don't put tags in the title of the question; things like "PHP -" are to be removed, not added. – user229044 Jan 24 '13 at 18:55
  • @meagar Yeah, that makes much sense on SO site. Thanks for pointing it out. – जलजनक Jan 24 '13 at 18:57

2 Answers2

2

Try the strtotime function

for($i=0;$i<5;$i++) {
  strtotime("+" . $i . " day");
}

You can also do it with custom dates:

for($i=0;$i<5;$i++) {
  strtotime("+" . $i . " day", mktime(0,0,0,date("m"),date("d"),date("y")));
}
Stephen
  • 215
  • 1
  • 11
0
sscanf(date('n j Y'),'%d %d %d',$m,$d,$y);
for ($i=0;$i<5;$i++)
{
    echo date('m/d/Y',mktime(0,0,0,$m,$d+$i,$y)).'<br />';
}

Result

07/01/2012
07/02/2012
07/03/2012
07/04/2012
07/05/2012
BiHon
  • 1
  • 1