Boffin
Boffin

Reputation: 569

Get interval from DatePeriod variable

As I understood from PHP manual page for DatePeriod class that it is purposed to store periods of time. I.e. interval with some point at time meaning start of the interval + optional recurrences.

With the following code I create $dp variable starting today with length of one month

$start = new DateTime();
$interval = new DateInterval('P1M');
$end = clone $start;
$end->add($interval);    
$dp = new DatePeriod($start, $interval, $end);

With following code I am printing all (at my example only one cause there are no recurrences) start dates of the period:

foreach ($dp as $d)
    var_dump($d->d);

My question is how can I get interval from $dp variable?

Upvotes: 2

Views: 1188

Answers (1)

Gordon
Gordon

Reputation: 317119

You cannot because DatePeriod does not expose any properties. If you need the Interval, reuse it from your $interval variable.

Upvotes: 2

Related Questions