Oihana PHP

addWeeks.php

Table of Contents

Functions

addWeeks()  : DateTimeImmutable
Returns a copy of a date shifted by a number of weeks.

Functions

addWeeks()

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

addWeeks(DateTimeInterface $date, int $weeks) : DateTimeImmutable

A new DateTimeImmutable is returned ; the source date is never modified. This is calendar arithmetic, equivalent to addDays( $date , $weeks * 7 ) : the wall-clock time of day is preserved, so across a DST transition the shift can differ from the same span expressed in hours (see addHours()). A negative $weeks shifts the date backwards.

Parameters
$date : DateTimeInterface

The source date.

$weeks : int

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

Tags
throws
DateMalformedStringException

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

example
use function oihana\core\date\addWeeks;

addWeeks( new DateTimeImmutable( '2026-01-01' ) , 2 )  ; // 2026-01-15
addWeeks( new DateTimeImmutable( '2026-01-01' ) , -1 ) ; // 2025-12-25
author

Marc Alcaraz (ekameleon)

since
1.2.0
Return values
DateTimeImmutable

A new immutable date shifted by $weeks weeks.

On this page

Search results