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 // Initialising a startDate with time $StartDate = new DateTime( '2019-05-16T00:00:00Z' );
// Initialising a DateInterval of 2 day $DateInterval = new DateInterval( 'P2D' );
// Initialising a endDate with time $EndDate = new DateTime( '2019-05-20T00:00:00Z' );
// Initialising a DatePeriod with startDate, DateInterval and // endDate $datePeriod = new DatePeriod( $StartDate , $DateInterval , $EndDate );
// Calling the getStartDate() function $StartDate = $datePeriod ->getStartDate();
// Getting the start date echo $StartDate ->format(DateTime::ISO8601);
?> |
Output:
2019-05-16T00:00:00+0000
Program 2:
<?php // Initialising a DatePeriod with a date of 2019-09-30, // time of 10 hours, 40 minutes and 44 seconds and with // day period of 14 days $datePeriod = new DatePeriod( 'R7/2019-09-30T10:40:44Z/P14D' );
// Calling the getStartDate() function $StartDate = $datePeriod ->getStartDate();
// Getting the start date echo $StartDate ->format(DateTime::ISO8601);
?> |
Output:
2019-09-30T10:40:44+0000
Reference: https://www.php.net/manual/en/dateperiod.getstartdate.php