user2894476
user2894476

Reputation: 43

PHP Time function issue

I need to add X days to current time

    echo date("d.m.Y H:i",time());
    echo "<br>";
    echo date("d.m.Y H:i",time()+5*24*60*60);

return correct results

    18.10.2013 14:22
    23.10.2013 14:22

but if i change 5 to 10 then

    18.10.2013 14:22
    28.10.2013 13:22

13:22 instead of 14:22 in result. 1 hour is missed.

What can be with it?

Upvotes: 4

Views: 148

Answers (3)

Jacko07
Jacko07

Reputation: 119

To add day to a date you can use DateTime (maybe will be easier)

php.net DateTime

Upvotes: 0

Adam
Adam

Reputation: 1371

Use strtotime function:

examples:

echo date("d.m.Y H:i",strtotime("+10 days")) ;
echo date("d.m.Y H:i",strtotime("+6 hours 30 seconds"))

strtotime function ignores the transition to winter time.

EXAMPLE IN USE

Upvotes: 0

spacebean
spacebean

Reputation: 1554

Daylight savings ends on the 27th of October (so we fall back an hour) which explains the issue you are seeing. Try it with another month and you will get the expected result!

Upvotes: 1

Related Questions