diffInHours.php
Table of Contents
Functions
- diffInHours() : int
- Returns the signed number of complete elapsed hours between two instants.
Functions
diffInHours()
Returns the signed number of complete elapsed hours between two instants.
diffInHours(DateTimeInterface $a, DateTimeInterface $b) : int
Absolute-duration (elapsed-time) arithmetic, computed straight from the Unix
timestamps — unlike diffInDays(), which is calendar-aware, this counts real hours.
Across a DST transition the two can disagree on what looks like the same nominal
span : from 2026-03-28 00:00 to 2026-03-30 00:00 Europe/Paris is 2 calendar days
(diffInDays()) but only 47 real hours (diffInHours()), the spring-forward gap on
2026-03-29 having shortened that day by one hour. The result is positive when $b
is later than $a, negative when it is earlier, truncated toward zero.
Parameters
- $a : DateTimeInterface
-
The starting instant.
- $b : DateTimeInterface
-
The ending instant.
Tags
Return values
int —The number of complete hours from $a to $b ; negative if $b is before $a.