Encodera

Thanks for reading!

Donate to the site — we work hard for you.

How to add days to a date

Short answer

The modify() method shifts the date and returns a new object:

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

Output:

06.02.2025

Months and years

The units are written in English: day, week, month, year:

<?php
 
$date = new DateTimeImmutable('2025-01-15');
 
echo $date->modify('+1 month')->format('d.m.Y'), ' ', $date->modify('-1 year')->format('d.m.Y');

Output:

15.02.2025 15.01.2024

Working days

The word weekdays skips Saturday and Sunday:

<?php
 
$friday = new DateTimeImmutable('2025-01-31');
 
echo $friday->modify('+1 weekdays')->format('d.m.Y');

Output:

03.02.2025

Functions used in this recipe

  • DateTimeImmutable — A date and time object that cannot be changed: every operation returns a new object.
  • strtotime — Turns a textual date description into a timestamp.
  • date — Formats a date and time.

Thanks for reading!

Donate to the site — we work hard for you.