Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'P' stand for in the DateInterval format?

Tags:

php

php-5.3

Consider the following example quoted from php manual for DateTime

<?php   $date = new DateTime('2000-01-20');   $date->sub(new DateInterval('P10D'));   echo $date->format('Y-m-d') . "\n"; ?> 

'D' is for days, what does the 'P' stand for in that formatting?

like image 777
Shrinath Avatar asked Feb 08 '12 06:02

Shrinath


People also ask

What is p in DateInterval PHP?

'P' stands for Period. see here http://php.net/manual/en/dateinterval.construct.php.

What is DateInterval?

The span of time between a specific start date and end date.

What is DateInterval in PHP?

PHP | DatePeriod getDateInterval() Function 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 )

What does P1Y mean?

P = static embargoes – so P1M would always be access previous month ongoing, or P1Y would always be access not available for current 12 months only past 1 year. “D” = days, “M” = months, “Y”= year.


2 Answers

From the manual

Interval specification.

The format starts with the letter P, for "period." Each duration period is represented by an integer value followed by a period designator. If the duration contains time elements, that portion of the specification is preceded by the letter T.

like image 172
Phil Avatar answered Oct 05 '22 03:10

Phil


'P' stands for Period. see here http://php.net/manual/en/dateinterval.construct.php

like image 38
Java Avatar answered Oct 05 '22 02:10

Java