PHP | DatePeriod getEndDate() Function
Last Updated :
12 Feb, 2021
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
$StartDate = new DateTime( '2019-09-30T00:00:00Z' );
$DateInterval = new DateInterval( 'P2D' );
$EndDate = new DateTime( '2019-10-02T00:00:00Z' );
$datePeriod = new DatePeriod( $StartDate , $DateInterval , $EndDate );
$endDate = $datePeriod ->getEndDate();
echo $endDate ->format(DateTime::ISO8601);
?>
|
Output:
2019-10-02T00:00:00+0000
Program 2:
php
<?php
$StartDate = new DateTime( '2019-09-30T00:00:00Z' );
$DateInterval = new DateInterval( 'P2D' );
$datePeriod = new DatePeriod( $StartDate , $DateInterval , 7);
var_dump( $datePeriod ->getEndDate());
?>
|
Reference: https://www.php.net/manual/en/dateperiod.getenddate.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...