Get Total Days from a PHP DateInterval

Last updated: November 30, 2026.

Read $interval->days for the total number of full days in an interval returned by diff(). The d field is the day component left after accounting for larger calendar components.

<?php

$zone = new DateTimeZone('UTC');
$start = new DateTimeImmutable('2026-04-01', $zone);
$end = new DateTimeImmutable('2026-05-01', $zone);
$interval = $start->diff($end);

printf("Months: %d, day component: %d\n", $interval->m, $interval->d);
printf("Total days: %d\n", $interval->days);
// Months: 1, day component: 0
// Total days: 30

Check where the interval came from

The example crosses one calendar month with no leftover days, so d is zero even though the two dates are 30 days apart. That is why using d alone can fail at month boundaries. Multiplying m by 30 also fails because months have different lengths.

The total is available when the interval came from DateTimeInterface::diff(). A duration created with new DateInterval('P1M') lacks a pair of dates, and its days property is false. Keep that value distinct from a legitimate total of zero by testing with === false.

Choose the sign and timezone deliberately

days gives the magnitude. Use invert to decide whether to negate it when the target is earlier than the start. For a date-only task such as measuring a booking, construct the endpoints at midnight in the business timezone and decide explicitly whether to count the ending date.

For elapsed time, compare timestamps or convert both endpoints to UTC before comparing clock intervals. A local calendar day during a daylight saving transition can represent 23 or 25 hours. Before deploying billing or reporting logic, test equal dates, reversed dates, a month boundary and a daylight saving transition when the timezone observes one.

Documentation

Related guides

Sergey Kornilov

Sergey Kornilov