date plus 4 Day results in wrong date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pospiech
Forum Newbie
Posts: 5
Joined: Fri Mar 12, 2004 8:35 am

date plus 4 Day results in wrong date

Post 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
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: date plus 4 Day results in wrong date

Post 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.
pospiech
Forum Newbie
Posts: 5
Joined: Fri Mar 12, 2004 8:35 am

Post 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
Post Reply