Oihana PHP

subWeeks.php

Table of Contents

Functions

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

Functions

subWeeks()

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

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

A new DateTimeImmutable is returned ; the source date is never modified. Equivalent to addWeeks( $date , -$weeks ) — see addWeeks() for the calendar-arithmetic semantics.

Parameters
$date : DateTimeInterface

The source date.

$weeks : int

The number of weeks to subtract.

Tags
throws
DateMalformedStringException

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

example
use function oihana\core\date\subWeeks;

subWeeks( new DateTimeImmutable( '2026-01-15' ) , 2 ) ; // 2026-01-01
author

Marc Alcaraz (ekameleon)

since
1.2.0
Return values
DateTimeImmutable

A new immutable date shifted backwards by $weeks weeks.

On this page

Search results