PHP Function Reference

PHP DatePeriod getStartDate() Method



The PHP DatePeriod::getStartDate() method returns the start date of the period.

Syntax

public DatePeriod::getStartDate()

Parameters

No parameter is required.

Return Value

Returns a DateTimeImmutable object when the DatePeriod is initialized with a DateTimeImmutable object as the start parameter. Returns a DateTime object otherwise.

Example: DatePeriod::getStartDate() example

The example below shows the usage of DatePeriod::getStartDate() method.

<?php
$start = new DateTime('2015-10-01');
$interval = new DateInterval('P7D');
$end = new DateTime('2015-10-31');
$recurrences = 4;
$iso = 'R4/2015-10-01T00:00:00Z/P7D';

//all of these periods are equivalent.
$period1 = new DatePeriod($start, $interval, $recurrences);
$period2 = new DatePeriod($start, $interval, $end);
$period3 = new DatePeriod($iso);

//getting the start date used for $period1
$date1 = $period1->getStartDate();
echo $date1->format('d-M-Y')."\n";

//getting the start date used for $period2
$date2 = $period2->getStartDate();
echo $date2->format('d-M-Y')."\n";

//getting the start date used for $period3
$date3 = $period3->getStartDate();
echo $date3->format('d-M-Y')."\n";
?>

The output of the above code will be:

01-Oct-2015
01-Oct-2015
01-Oct-2015

❮ PHP Date and Time Reference