Simmo Posted March 31, 2011 Share Posted March 31, 2011 Hi, Something strange has happend today. I am from the UK the date is March 31st so I am using timezone: date_default_timezone_set('UTC'); I capture the date: $date = date("Y-m-d"); Add a month to the date: date("Y-m-d", strtotime("+1 Month", strtotime($date))) And its comming out as May. If I capture the date through the URL which I do when navigating back: $date = $_GET['date']; Its works and says April Can anyone please advise me on why this is happening. Thanks Quote Link to comment Share on other sites More sharing options...
btherl Posted March 31, 2011 Share Posted March 31, 2011 Is date("Y-m-d") producing what you expect? Have you printed it out? Quote Link to comment Share on other sites More sharing options...
Simmo Posted March 31, 2011 Author Share Posted March 31, 2011 Hi, Yes it is, any suggestions? Cheers Quote Link to comment Share on other sites More sharing options...
salathe Posted March 31, 2011 Share Posted March 31, 2011 See this blog post from the guy who maintains PHPs date/time related functions: http://derickrethans.nl/obtaining-the-next-month-in-php.html Quote Link to comment Share on other sites More sharing options...
Simmo Posted March 31, 2011 Author Share Posted March 31, 2011 Thanks for that, it all makes sense. Here is my solution: $month = date("m"); $year = date("Y"); date("Y-m-d", strtotime("+1 Month", strtotime(date("Y-m-d", strtotime($year.$month.'01'.' 00:00:00'))))) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 31, 2011 Share Posted March 31, 2011 strtotime() and date() are fairly slow and you have a ton of extra ones. This is all you need - date("Y-m-d", strtotime(date('Y-m') . "-01 +1 Month")); 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.