Open In App

PHP | DatePeriod getEndDate() Function

Last Updated : 12 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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
 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads