Oihana PHP

endOfMonth.php

Table of Contents

Functions

endOfMonth()  : DateTimeImmutable
Returns the last representable instant of the month containing a date.

Functions

endOfMonth()

Returns the last representable instant of the month containing a date.

endOfMonth(DateTimeInterface $date) : DateTimeImmutable

A new DateTimeImmutable is returned, set to the last day of the month at 23:59:59.999999 (microseconds included) ; the source date is never modified. The timezone of the returned value is the one carried by $date. The last day of the month is computed with daysInGregorianMonth(), so leap years are handled correctly.

Parameters
$date : DateTimeInterface

The source date.

Tags
example
use function oihana\core\date\endOfMonth;

endOfMonth( new DateTimeImmutable( '2026-02-05' ) ) ; // 2026-02-28 23:59:59.999999
endOfMonth( new DateTimeImmutable( '2024-02-05' ) ) ; // 2024-02-29 23:59:59.999999 (leap year)
author

Marc Alcaraz (ekameleon)

since
1.2.0
Return values
DateTimeImmutable

A new immutable date, at the end of the same month.

On this page

Search results