krishnik007 Posted August 17, 2010 Share Posted August 17, 2010 Hi, I want to calculate the future month, i have used following code to calculate the date $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime('2010-01-31')) . " +3 month")); It gives me 2010-03-03 But i need to get 2010-02-28 OR just month is enough like 2010-02 Thank you Nikhil Quote Link to comment https://forums.phpfreaks.com/topic/210952-future-date-calculation/ Share on other sites More sharing options...
Adam Posted August 17, 2010 Share Posted August 17, 2010 You want to get the year and month in 3 months time? $month = date('Y-m', strtotime('+ 3 months')); Quote Link to comment https://forums.phpfreaks.com/topic/210952-future-date-calculation/#findComment-1100289 Share on other sites More sharing options...
krishnik007 Posted August 17, 2010 Author Share Posted August 17, 2010 You want to get the year and month in 3 months time? $month = date('Y-m', strtotime('+ 3 months')); Yes that right adam. I just want to find out the year and month in 3 months time. $month = date('Y-m', strtotime('+ 3 months')); How can i pass a date to above function suppose i want to find out the value after 3 month of the following date 2010-01-31 How can i do that.. Sorry for my poor english Nick Quote Link to comment https://forums.phpfreaks.com/topic/210952-future-date-calculation/#findComment-1100293 Share on other sites More sharing options...
JasonLewis Posted August 17, 2010 Share Posted August 17, 2010 If you're trying to get it from a specific date such as in your example (2010-01-31), and not 3 months from the current date, you can use mktime. <?php $from = '2010-10-01'; list($year, $month, $day) = explode('-', $from); $date = date('Y-m-d', mktime(0, 0, 0, $month + 3, $day, $year)); echo $date; ?> Quote Link to comment https://forums.phpfreaks.com/topic/210952-future-date-calculation/#findComment-1100299 Share on other sites More sharing options...
Adam Posted August 17, 2010 Share Posted August 17, 2010 Or.. $month = date('Y-m', strtotime('+ 3 months', strtotime('2010-01-31'))); Of course I just realised in your first example, the date returned is correct. There's no 31st of February so it's carried on to the next month; unfortunately this is the behaviour of strtottime(). Quote Link to comment https://forums.phpfreaks.com/topic/210952-future-date-calculation/#findComment-1100306 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.