230 of 410 menu

The date_add Function

The date_add function adds a time interval to a date object. The first parameter accepts a DateTime object, the second - a DateInterval object.

Syntax

date_add(DateTime $object, DateInterval $interval);

Example

Add 10 days to the specified date:

<?php $date = new DateTime('2025-06-15'); $interval = new DateInterval('P10D'); date_add($date, $interval); echo $date->format('Y-m-d'); ?>

Code execution result:

'2025-06-25'

Example

Add 1 year and 2 months to the date:

<?php $date = new DateTime('2025-03-20'); $interval = new DateInterval('P1Y2M'); date_add($date, $interval); echo $date->format('Y-m-d'); ?>

Code execution result:

'2026-05-20'

Example

The date_create function returns a DateTime object. You can rewrite the code in a mixed style, partially OOP and partially functional:

<?php $date = date_create('2025-03-20'); $interval = new DateInterval('P1Y2M'); date_add($date, $interval); echo date_format($date, 'Y-m-d'); ?>

Code execution result:

'2026-05-20'

See Also

  • the date_add function,
    in a functional style
  • the date_sub function,
    in an OOP style
byenru