abdfahim Posted April 5, 2010 Share Posted April 5, 2010 Dear Developers, I am facing a starnge problem. I wan to subtract 2 days from a given date and so I use the code below. $dateto = strtotime("2010-03-30"); echo Date("Y-m-d",$dateto-(2*86400)); This works fine for everything accept 29th March, 2010 and 30th March, 2010 !!! That is, the output of the simple program above is .. 2010-03-25 when $dateto=2010-03-27 2010-03-26 when $dateto=2010-03-28 2010-03-26 when $dateto=2010-03-29 2010-03-27 when $dateto=2010-03-30 2010-03-29 when $dateto=2010-03-31 2010-03-30 when $dateto=2010-04-01 2010-04-27 when $dateto=2010-04-29 2010-04-28 when $dateto=2010-04-30 Quote Link to comment Share on other sites More sharing options...
Deoctor Posted April 5, 2010 Share Posted April 5, 2010 hai i dont see any difference, i am getting the correct results when i run the same code.. are u sure u have deleted ur cookies from the browser and run the code.. Quote Link to comment Share on other sites More sharing options...
abdfahim Posted April 5, 2010 Author Share Posted April 5, 2010 well, some 20 users are facing this problem so i am not sure whether anything to do with cookies. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted April 5, 2010 Share Posted April 5, 2010 change ur date function like this and try it on ur local machine..by changing the date of the system.. $dateto=strtotime(date("Y-m-d")); Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 5, 2010 Share Posted April 5, 2010 Well, I'm not quite sure why you are getting "those" results. I get different errors, but I know why - daylight savings time. If that is your problem you can fix this by setting the time to the middle of the day. And you can get the correct results with one function using a more "natural" conversion of "-2 day". echo Date("Y-m-d", strtotime("2010-03-30 12:00:00PM -2 day")); Quote Link to comment Share on other sites More sharing options...
abdfahim Posted April 5, 2010 Author Share Posted April 5, 2010 Thanks guys, I think its something related with DST. Anyway, I change that to get from mid-day. Thanks both of you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.