Hello, i have a date which i m getting from database in the format of "dd/mm/YYYY", now the thing i want to do is to increment that date by one continuously....
e.g.
$date = "25/12/2009";
then it should be
26/12/2009
27/12/2009...
and so on..
increment date one by one
Moderator: General Moderators
Re: increment date one by one
This will get you started:
Will output:
25-12-2009
26-12-2009
Code: Select all
$date = "25/12/2009";
$a =( explode ("/",$date));
$day = $a[0];
$mo = $a[1];
$yr = $a[2];
//mktime(hour,minute,second,month,day,year,is_dst)
echo(date("d-m-Y",mktime(0,0,0,$mo,$day,$yr))."<br />");
$day = $day+1;
echo(date("d-m-Y",mktime(0,0,0,$mo,$day,$yr))."<br />");
25-12-2009
26-12-2009
Re: increment date one by one
Also:
You can replace +1 with a variable that is incremented in a loop. I'm not sure if it will work with your format though.
Code: Select all
echo date('d/m/Y',strtotime($date . " +1 day")); Re: increment date one by one
pytrin, your code:
yields this:
01/01/1970
... which is incorrect.
Code: Select all
$date = "25/12/2009";
echo date('d/m/Y',strtotime($date . " +1 day"));
01/01/1970
... which is incorrect.
Re: increment date one by one
As I said, I wasn't sure if it will work with his format. It works with the standard "Y-m-d" (SQL format)
Re: increment date one by one
Code: Select all
echo date('d/m/Y', strtotime(str_replace('/', '-', $date) . " +1 day"));Re: increment date one by one
hey 1st one & last one nicely worked, thanx guys...
& thanx to all of one who replied....
& thanx to all of one who replied....