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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.