Oihana PHP

addDays.php

Table of Contents

Functions

addDays()  : DateTimeImmutable
Returns a copy of a date shifted by a number of days.

Functions

addDays()

Returns a copy of a date shifted by a number of days.

addDays(DateTimeInterface $date, int $days) : DateTimeImmutable

A new DateTimeImmutable is returned ; the source date is never modified. A negative $days shifts the date backwards.

Parameters
$date : DateTimeInterface

The source date.

$days : int

The number of days to add (negative to subtract).

Tags
throws
DateMalformedStringException

Never thrown in practice (the modifier is always well-formed).

example
use function oihana\core\date\addDays;

addDays( new DateTimeImmutable( '2026-01-01' ) , 5 )  ; // 2026-01-06
addDays( new DateTimeImmutable( '2026-01-01' ) , -1 ) ; // 2025-12-31
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
DateTimeImmutable

A new immutable date shifted by $days days.

On this page

Search results