PHP | DatePeriod getStartDate() Function
Last Updated :
30 Sep, 2019
The DatePeriod::getStartDate() function is an inbuilt function in PHP which is used to return the start date of the given date period.
Syntax:
DateTimeInterface DatePeriod::getStartDate( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the start date of the given date period.
Below programs illustrate the DatePeriod::getStartDate() function in PHP:
Program 1:
<?php
$StartDate = new DateTime( '2019-05-16T00:00:00Z' );
$DateInterval = new DateInterval( 'P2D' );
$EndDate = new DateTime( '2019-05-20T00:00:00Z' );
$datePeriod = new DatePeriod( $StartDate , $DateInterval , $EndDate );
$StartDate = $datePeriod ->getStartDate();
echo $StartDate ->format(DateTime::ISO8601);
?>
|
Output:
2019-05-16T00:00:00+0000
Program 2:
<?php
$datePeriod = new DatePeriod( 'R7/2019-09-30T10:40:44Z/P14D' );
$StartDate = $datePeriod ->getStartDate();
echo $StartDate ->format(DateTime::ISO8601);
?>
|
Output:
2019-09-30T10:40:44+0000
Reference: https://www.php.net/manual/en/dateperiod.getstartdate.php
Share your thoughts in the comments
Please Login to comment...