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

PHP time function issue

I need to add X days to the 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 as a result. 1 hour missed.

What could be wrong with him?

+4
source share
3 answers

Daylight ends October 27th (so we go back an hour), which explains the problem you see. Try another month and you will get the expected result!

+1
source

Use the 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"))

The strtotime function ignores daylight saving time.

EXAMPLE IN USE

0
source

To add a day to a date, you can use DateTime (it might be easier)

php.net DateTime

0
source

All Articles