Friday, October 10, 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
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7100 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS