catchy Posted August 31, 2009 Share Posted August 31, 2009 Hey, I have an app that generates an array of 27 days from any given day at the start, to display a gannt chart of 4 weeks in advance. BUT as of today (31 August 2009), September goes missing! It jumps straight to 01 OCt, 02 Oct, and so on. Here's the code ($days is the array): for($i=0; $i<=27; $i++) { $last_day = date('d',mktime(date('h'), date('i'), date('s'), date('m'), date('d',mktime(date('H'),date('i'),date('s'),$this_month,$this_day+$i,$this_year)), date('Y'))); $days[] = $last_day; $last_month = date('m',mktime(date('h'), date('i'), date('s'), date('m',mktime(date('H'),date('i'),date('s'),$this_month,$this_day+$i,$this_year)), date('j'), date('Y'))); $last_year = date('Y',mktime(date('h'), date('i'), date('s'), date('m'), date('d'), date('Y',mktime(date('H'),date('i'),date('s'),$this_month,$this_day+$i,$this_year)))); } As you can see, it uses mktime to add an increasing ($i) no. of days to the $last_month variable. BUT it jumps straight from 31/08/09 to 01/10/09. Help! Any ideas? Thanks heaps. Quote Link to comment Share on other sites More sharing options...
btherl Posted August 31, 2009 Share Posted August 31, 2009 That code is just too difficult to understand. Can you do it without nesting function calls? It'll be more lines but it'll improve readability no end. Then it'll be easier to find the bug. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 31, 2009 Share Posted August 31, 2009 Leading zeros make a number OCTAL in php and 09 is not a valid OCTAL number so it is skipped. You should only apply leading zeros to a number when you display it. Quote Link to comment Share on other sites More sharing options...
unibroue Posted August 31, 2009 Share Posted August 31, 2009 quick reply to this thread! i have the same problem with that code : $nextmonth = date("Y-n-d", mktime(0,0,0,date("n")+1,date("d"),date("Y"))); return october 1 insted of september 1 ... ... Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 31, 2009 Share Posted August 31, 2009 Also, when you specify a day number that does not exist in a specific month, it goes to the next month. Quote Link to comment Share on other sites More sharing options...
unibroue Posted August 31, 2009 Share Posted August 31, 2009 Also, when you specify a day number that does not exist in a specific month, it goes to the next month. That's the solution ... thanks! Quote Link to comment Share on other sites More sharing options...
catchy Posted August 31, 2009 Author Share Posted August 31, 2009 @PFMaBiSmAd Thanks a million, I didn't know that about octal values and non-existent day numbers. This was code I've inherited, and it's way overcomplicated. Turns out this line (for months) does the trick: date('m',mktime(0, 0, 0, $this_month, $this_day+$i, $this_year)); Thanks again. 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.