Encodera

Thanks for reading!

Donate to the site — we work hard for you.

How to find the difference between two dates

Short answer

The diff() method returns the difference between two dates. The total number of days is in the days property:

<?php
 
$start = new DateTime('2025-01-01');
$end = new DateTime('2025-03-15');
 
echo $start->diff($end)->days;

Output:

73

Years, months and days

The difference is also available in parts — for example, to compute an age:

<?php
 
$diff = (new DateTime('2020-05-10'))->diff(new DateTime('2025-03-15'));
 
echo $diff->y, ' ', $diff->m, ' ', $diff->d;

Output:

4 10 5

Adding days to a date

The modify() method shifts a date by a given interval and takes month lengths into account:

<?php
 
$date = new DateTime('2025-01-30');
$date->modify('+5 days');
 
echo $date->format('Y-m-d');

Output:

2025-02-04

Thanks for reading!

Donate to the site — we work hard for you.