Parse both inputs and use DateTimeInterface::diff() for a calendar-aware interval.
$start = new DateTimeImmutable('2026-09-14 09:00');
$end = new DateTimeImmutable('2026-09-16 17:30');
$interval = $start->diff($end);
echo $interval->format('%a days %h hours %i minutes');Current example first; the detailed examples and demos below are retained for additional learning and comparison.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.