Jump to content

[SOLVED] Help please! mktime is skipping September 09!


catchy

Recommended Posts

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.

 

@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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.