4

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?

7
  • 5
    Daylight Savings Time? You might have hit a boundary there. Commented Oct 18, 2013 at 11:26
  • 27th October is time-shift to winter time. Commented Oct 18, 2013 at 11:28
  • What happens if you'd use the following code? $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day"); Commented Oct 18, 2013 at 11:28
  • 1
    Try ch1.php.net/manual/en/datetime.add.php instead. Commented Oct 18, 2013 at 11:28
  • 1
    @str learn something new everyday - have been doing that for years "just incase" thanks Commented Oct 18, 2013 at 11:32

3 Answers 3

1

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!

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

php.net DateTime

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.