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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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 ?> Quote Link to comment 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? Quote Link to comment 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 ?> Quote Link to comment Share on other sites More sharing options...
aebstract Posted January 6, 2009 Author Share Posted January 6, 2009 Thanks! 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.