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?
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?
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")));
}
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