PHP › Date & Time Handling
How should an application handle daylight saving time transitions correctly when performing date arithmetic across such a transition?
AdvancedAnswer
Daylight saving time transitions can cause certain local times to either not exist at all or occur twice within a single day, meaning date arithmetic performed using local time zones can sometimes produce unexpected results, and the safest approach is generally to perform calculations in UTC, which has no daylight saving transitions, converting only to a local time zone at the point where the date is actually displayed to a user, ensuring consistent, predictable behavior regardless of when a daylight saving transition happens to occur.
$utc = new DateTime('2026-03-08 12:00:00', new DateTimeZone('UTC'));
$utc->modify('+1 day');
$local = clone $utc;
$local->setTimezone(new DateTimeZone('America/New_York'));Real-world example A scheduling application performing recurring appointment calculations always adds time intervals while working in UTC internally, only converting to the customer's local time zone for final display, completely avoiding a class of bugs that previously occurred around daylight saving time transitions.