User Contributed Notes 4 notes

Note that the sub() and add() methods will modify the value of the object you're calling the method on! This is very untypical for a method that returns a value of its own type. You could misunderstand it that the method would return a new instance with the modified value, but in fact it modifies itself! This is undocumented here. (Only a side note on procedural style mentions it, but it obviously does not apply to object oriented style.)

This is particularly undesirable -- in this example you make a datetime, use sub() to make it a relative time in the past, and then date->diff() to confirm the difference. But the diff() inadvertendly makes the difference 2x.

Keep in mind that this method can work incorrectly when the daylight saving time is changing to wintertime.An example is when you have got a loop and your subtracting 1 hour from your time in it. On one day you are actually subtracting 1 hour and the computer adds 1 - the infinitive loop is created.And on the other day you would actually subtract 2 hours.