PHP Velho Oeste 2024

DatePeriod::getEndDate

(PHP 5 >= 5.6.5, PHP 7, PHP 8)

DatePeriod::getEndDate Obtener la fecha final

Descripción

Estilo orientado a objetos

public DatePeriod::getEndDate(): DateTimeInterface

Obtiene la fecha final del periodo.

Parámetros

Esta función no tiene parámetros.

Valores devueltos

Devuelve null si el objeto DatePeriod no posee una fecha final. Por ejemplo, cuando se inicializó con el parámetro recurrences, o el parámetro isostr sin una fecha final.

Devuelve un objeto DateTimeImmutable cuando el objeto DatePeriod se inicializó con un objeto DateTimeImmutable para el parámetro end.

De lo contrario, devuelve un objeto DateTime.

Ejemplos

Ejemplo #1 Ejemplo de DatePeriod::getEndDate()

<?php
$periodo
= new DatePeriod(
new
DateTime('2016-05-16T00:00:00Z'),
new
DateInterval('P1D'),
new
DateTime('2016-05-20T00:00:00Z')
);
$inicio = $periodo->getEndDate();
echo
$inicio->format(DateTime::ISO8601);
?>

El resultado de los ejemplos sería:

2016-05-20T00:00:00+0000

Ejemplo #2 DatePeriod::getEndDate() sin una fecha final

<?php
$periodo
= new DatePeriod(
new
DateTime('2016-05-16T00:00:00Z'),
new
DateInterval('P1D'),
7
);
var_dump($periodo->getEndDate());
?>

El resultado del ejemplo sería:

NULL

Ver también

add a note add a note

User Contributed Notes 1 note

up
2
mauro dot chojrin at leewayweb dot com
6 years ago
Why can't I ask for end date on a period based on recurrences?

I understand I never specified such a property, but it's a really easy calculation... shouldn't it be built in?
To Top