aebstract Posted January 6, 2009 Share Posted January 6, 2009 Simple question, how do you take a month.. be it the current month or any month you have stored in a variable and add one month to it to get the next month. Same with previous month. If I have April, I want to be able to get March and May. Thanks Link to comment https://forums.phpfreaks.com/topic/139681-solved-adding-1-to-month/ Share on other sites More sharing options...
gevans Posted January 6, 2009 Share Posted January 6, 2009 How are you storing the month? timestamp, text? Link to comment https://forums.phpfreaks.com/topic/139681-solved-adding-1-to-month/#findComment-730815 Share on other sites More sharing options...
aebstract Posted January 6, 2009 Author Share Posted January 6, 2009 Basically, I'm using the current month as the starting point and then can either go up or down a month from there. So I am open to storing it however, it won't be stored in a database or anything. Link to comment https://forums.phpfreaks.com/topic/139681-solved-adding-1-to-month/#findComment-730820 Share on other sites More sharing options...
gevans Posted January 6, 2009 Share Posted January 6, 2009 Ok, have a look at the following and see if it makes sense; <?php $currentMonth = date("m",time()); echo date("F", mktime(0, 0, 0, $currentMonth, 0, 0));//prints the current month echo "<br />"; echo date("F", mktime(0, 0, 0, ($currentMonth+1), 0, 0));//prints the next month echo "<br />"; echo date("F", mktime(0, 0, 0, ($currentMonth-1), 0, 0));//prints the previous month ?> Link to comment https://forums.phpfreaks.com/topic/139681-solved-adding-1-to-month/#findComment-730823 Share on other sites More sharing options...
aebstract Posted January 6, 2009 Author Share Posted January 6, 2009 That works, is it hard to roll back the year to 2008 if your current month is jan 09? Link to comment https://forums.phpfreaks.com/topic/139681-solved-adding-1-to-month/#findComment-730825 Share on other sites More sharing options...
gevans Posted January 6, 2009 Share Posted January 6, 2009 I've changed the code for you try this; <?php $today = getdate(); echo date("F Y");//this month echo "<br />"; echo date("F Y",strtotime('+1 month'));//next month echo "<br />"; echo date("F Y",strtotime('-1 month'));//last month ?> Link to comment https://forums.phpfreaks.com/topic/139681-solved-adding-1-to-month/#findComment-730835 Share on other sites More sharing options...
aebstract Posted January 6, 2009 Author Share Posted January 6, 2009 Thanks! Link to comment https://forums.phpfreaks.com/topic/139681-solved-adding-1-to-month/#findComment-730836 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.