PHP | DatePeriod getDateInterval() Function
Last Updated :
30 Sep, 2019
The DatePeriod::getDateInterval() function is an inbuilt function in PHP which is used to return the date interval for the given date period.
Syntax:
DateInterval DatePeriod::getDateInterval( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the DateInterval object of the given date period.
Below programs illustrate the DatePeriod::getDateInterval() function in PHP:
Program 1:
<?php
$DP = new DatePeriod( 'R7/2019-09-25T12:30:00Z/P5D' );
$dateInterval = $DP ->getDateInterval();
echo $dateInterval ->format( '%d days' );
?>
|
Program 2:
<?php
$start_date = new DateTime( '2019-09-01' );
$interval = new DateInterval( 'P5D' );
$end_date = new DateTime( '2019-09-30' );
$DP = new DatePeriod( $start_date , $interval , $end_date );
$dateInterval = $DP ->getDateInterval();
echo $dateInterval ->format( '%d days' );
?>
|
Reference: https://www.php.net/manual/en/dateperiod.getdateinterval.php
Share your thoughts in the comments
Please Login to comment...