Thursday, June 11, 2026
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
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS