Friday, December 12, 2025
HomeLanguagesPHP | DatePeriod getEndDate() Function

PHP | DatePeriod getEndDate() Function

The DatePeriod::getEndDate() function is an inbuilt function in PHP which is used to return the end date. If the given date period does not have any end date then it returns NULL.
Syntax: 
 

DateTimeInterface DatePeriod::getEndDate( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns the end date of the given date period.

Below programs illustrate the DatePeriod::getEndDate() function in PHP:
Program 1: 

php




<?php
  
// Initialising a startDate with time
$StartDate = new DateTime('2019-09-30T00:00:00Z');
  
// Initialising a DateInterval of 2 day
$DateInterval = new DateInterval('P2D');
  
// Initialising a endDate with time
$EndDate = new DateTime('2019-10-02T00:00:00Z');
  
// Initialising a DatePeriod with startDate, DateInterval and
// endDate
$datePeriod = new DatePeriod( $StartDate, $DateInterval, $EndDate);
      
// Calling the getendDate() function
$endDate = $datePeriod->getEndDate();
  
// Getting the start date
echo $endDate->format(DateTime::ISO8601);
?>


Output: 

2019-10-02T00:00:00+0000

 

Program 2: 

php




<?php
  
// Initialising a startDate with time
$StartDate = new DateTime('2019-09-30T00:00:00Z');
  
// Initialising a DateInterval of 2 day
$DateInterval = new DateInterval('P2D');
  
// Initialising a DatePeriod with startDate, DateInterval
// and without endDate
$datePeriod = new DatePeriod( $StartDate, $DateInterval, 7);
  
// Getting the start date
var_dump($datePeriod->getEndDate());
?>


Output: 

NULL

 

Reference: https://www.php.net/manual/en/dateperiod.getenddate.php
 

RELATED ARTICLES

Most Popular

Dominic
32445 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12029 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7199 POSTS0 COMMENTS
Thapelo Manthata
6895 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS