Page 1 of 1

date plus 4 Day results in wrong date

Posted: Wed Mar 17, 2004 5:40 am
by pospiech
I have a date "01.07.2004" and want to get "05.07.2004". This is done in the following way:

Here it works:

Code: Select all

$datum_plus_vier_tage = mktime(0,0,0,"01"+4,"07","2004"); 
$enddatum = strftime('%m.%d.%Y', $datum_plus_vier_tage); 
echo $enddatum;
gives: 05.07.2004


Here the results is crap:

Code: Select all

$datum_plus_vier_tage = mktime(0,0,0,"24"+4,"01","2004"); 
$enddatum = strftime('%m.%d.%Y', $datum_plus_vier_tage); 
echo $enddatum;
gives: 04.01.2006

What do I do wrong ?

Matthias

Re: date plus 4 Day results in wrong date

Posted: Wed Mar 17, 2004 8:43 am
by TheBentinel.com
pospiech wrote:I have a date "01.07.2004" and want to get "05.07.2004". This is done in the following way:


Here the results is crap:

Code: Select all

$datum_plus_vier_tage = mktime(0,0,0,"24"+4,"01","2004"); 
$enddatum = strftime('%m.%d.%Y', $datum_plus_vier_tage); 
echo $enddatum;
gives: 04.01.2006

What do I do wrong ?

Matthias
mktime is Month-Day-Year (like the U.S. standard), so change your line to:
$datum_plus_vier_tage = mktime(0,0,0,"01", "24"+4,"2004");

I think your first example didn't work either, it actually added 4 months to your date, instead of 4 days.

Hope it helps.

Posted: Wed Mar 17, 2004 12:11 pm
by pospiech
Yes it does! - seems that I could have worked on that code for the next couple of hours and would not have found the problem...

Matthias