Wednesday, November 20, 2024
Google search engine
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

Recent Comments