addHours.php
Table of Contents
Functions
- addHours() : DateTimeImmutable
- Returns a copy of a date shifted by a number of hours.
Functions
addHours()
Returns a copy of a date shifted by a number of hours.
addHours(DateTimeInterface $date, int $hours) : DateTimeImmutable
A new DateTimeImmutable is returned ; the source date is never modified. This is
absolute-duration (elapsed-time) arithmetic : across a DST transition, addHours()
shifts by exactly that many real hours, which can land on a different wall-clock time
than a calendar shift of the same nominal span. For example, from
2026-03-29 01:30:00 Europe/Paris (just before the spring-forward gap), addHours( $d , 1 )
lands on 03:30:00 +02:00 — a two-hour wall-clock jump for one real hour elapsed —
where addDays( $d , 1 ) keeps the same wall-clock time on the next day. A negative
$hours shifts the date backwards.
Parameters
- $date : DateTimeInterface
-
The source date.
- $hours : int
-
The number of hours to add (negative to subtract).
Tags
Return values
DateTimeImmutable —A new immutable date shifted by $hours hours.