[PHP] Need help on increment date
HI all I need help to increment date in php. I found this code helpful $date = strtotime(+1 day, strtotime(2007-02-28)); echo date(Y-m-d, $date); But when My date is 2008-02-28 this code give output 2012-03-01. But it should be 2008-02-29. Where I am getting wrong. -- Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck 2048R/89C932E1 http://goo.gl/TkP5U Volunteer, FOSS Bangladesh http://fossbd.org/ Mozilla Repshttp://reps.mozilla.org 01199151550
Re: [PHP] Need help on increment date
On 24 May 2012, at 08:18, Md Ashickur Rahman Noor wrote: I need help to increment date in php. I found this code helpful $date = strtotime(+1 day, strtotime(2007-02-28)); echo date(Y-m-d, $date); But when My date is 2008-02-28 this code give output 2012-03-01. But it should be 2008-02-29. Where I am getting wrong. Works fine for me: http://dev.stut.net/php/increment_date.php Have you extracted the above from other code, or are you seeing this behaviour with just those two lines? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need help on increment date
Get this from herehttp://stackoverflow.com/questions/660501/simplest-way-to-increment-a-date-in-php -- Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck 2048R/89C932E1 http://goo.gl/TkP5U Volunteer, FOSS Bangladesh http://fossbd.org/ Mozilla Repshttp://reps.mozilla.org 01199151550 Have you extracted the above from other code, or are you seeing this behaviour with just those two lines? -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/
Re: [PHP] Need help on increment date
It works for me too. I tell you two things, a) make sure there is a space after +1 day. So it should look like +1 day . This ensures that the unix time is not concatenated with day. b) calling strtotime 2 times is not a great solution. You can all it once only. Like this, $date = strtotime http://www.php.net/strtotime(+1 day 2008-02-28); // better to call this, as the order is quite logical $date = strtotime http://www.php.net/strtotime(2008-02-28 +1 day); -- Shiplu.Mokadd.im ImgSign.com | A dynamic signature machine Innovation distinguishes between follower and leader
Re: [PHP] Need help on increment date
It works. Thanks you two. Thanks Shiplu bro for the advice. -- Dedicated Linux Forum in Bangladesh http://goo.gl/238Ck 2048R/89C932E1 http://goo.gl/TkP5U Volunteer, FOSS Bangladesh http://fossbd.org/ Mozilla Repshttp://reps.mozilla.org 01199151550 On 24 May 2012 15:08, shiplu shiplu@gmail.com wrote: $date = strtotime http://www.php.net/strtotime(2008-02-28 +1 day);