refiking Posted September 17, 2008 Share Posted September 17, 2008 I am using a calendar script that uses the current time to show the current month's calendar. What I am trying to do is get the next month's calendar to be returned. I've tried to use the mktime function, but am at a loss so far. What do I need to do? Here's what I have so far. $time = time(); $nmonth = time("+1 Month"); Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/ Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Use the strtotime() function like this: $time = time(); $nmonth = strtotime($time." +1 Month"); Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/#findComment-644127 Share on other sites More sharing options...
Maq Posted September 17, 2008 Share Posted September 17, 2008 $nextmonth = mktime(0, 0, 0, date("m")+1, date("d"), date("Y")); Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/#findComment-644129 Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 If you do it that way, you have the potential to end up with a month 13, which it will probably understand as 1 plus one year, but maybe not. Your best bet is to use strtotime. Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/#findComment-644130 Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 If you do it that way, you have the potential to end up with a month 13, which it will probably understand as 1 plus one year, but maybe not. Your best bet is to use strtotime. You don't even need the time() function like in your code...just strtotime(). It implicitly uses 'now' as the default timestamp: <?php $nextmonth = strtotime('+1 month'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/#findComment-644145 Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Yes, however, if you wanted to change the $time variable to something other than the current time, the $nextmonth var would be one more month from $time, making it a little more flexible. Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/#findComment-644152 Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 In that case, you pass the timestamp in as the second parameter, don't concatenate it to the strtotime() string. Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/#findComment-644159 Share on other sites More sharing options...
refiking Posted September 17, 2008 Author Share Posted September 17, 2008 OK. I used Darkwater's code to get the future months. I have 6 months of calendars on the page. Everything worked great up until January. It showed Jan 2009. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/#findComment-644209 Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 I was under the impression that after 2008 came 2009. Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/#findComment-644211 Share on other sites More sharing options...
refiking Posted September 17, 2008 Author Share Posted September 17, 2008 It does. Complete operator error. The calendar has two seperate $nmonth variables. The first (which I overlooked) is for the Header Line and the second one is for the actual calendar. Switched it and now works perfectly. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/124706-solved-trying-to-use-time-function-to-return-next-month/#findComment-644231 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.