Oihana PHP

subHours.php

Table of Contents

Functions

subHours()  : DateTimeImmutable
Returns a copy of a date shifted backwards by a number of hours.

Functions

subHours()

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

subHours(DateTimeInterface $date, int $hours) : DateTimeImmutable

A new DateTimeImmutable is returned ; the source date is never modified. Equivalent to addHours( $date , -$hours ) — see addHours() for the elapsed-time semantics across a DST transition.

Parameters
$date : DateTimeInterface

The source date.

$hours : int

The number of hours to subtract.

Tags
throws
DateMalformedStringException

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

example
use function oihana\core\date\subHours;

subHours( new DateTimeImmutable( '2026-01-01 05:00:00' ) , 5 ) ; // 2026-01-01 00:00:00
author

Marc Alcaraz (ekameleon)

since
1.2.0
Return values
DateTimeImmutable

A new immutable date shifted backwards by $hours hours.

On this page

Search results