Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

dateinterval.createfromdatestring(3) [php man page]

DATEINTERVAL.CREATEFROMDATESTRING(3)					 1				      DATEINTERVAL.CREATEFROMDATESTRING(3)

DateInterval::createFromDateString - Sets up a DateInterval from the relative parts of the string

SYNOPSIS
publicstatic DateInterval DateInterval::createFromDateString (string $time) DESCRIPTION
Uses the normal date parsers and sets up a DateInterval from the relative parts of the parsed string. PARAMETERS
o $time - A date with relative parts. Specifically, the relative formats supported by the parser used for strtotime(3) and DateTime will be used to construct the DateInterval. EXAMPLES
Example #1 Parsing valid date intervals <?php // Each set of intervals is equal. $i = new DateInterval('P1D'); $i = DateInterval::createFromDateString('1 day'); $i = new DateInterval('P2W'); $i = DateInterval::createFromDateString('2 weeks'); $i = new DateInterval('P3M'); $i = DateInterval::createFromDateString('3 months'); $i = new DateInterval('P4Y'); $i = DateInterval::createFromDateString('4 years'); $i = new DateInterval('P1Y1D'); $i = DateInterval::createFromDateString('1 year + 1 day'); $i = new DateInterval('P1DT12H'); $i = DateInterval::createFromDateString('1 day + 12 hours'); $i = new DateInterval('PT3600S'); $i = DateInterval::createFromDateString('3600 seconds'); ?> RETURN VALUES
Returns a new DateInterval instance. PHP Documentation Group DATEINTERVAL.CREATEFROMDATESTRING(3)

Check Out this Related Man Page

DATETIME.DIFF(3)							 1							  DATETIME.DIFF(3)

DateTime::diff - Returns the difference between two DateTime objects

       Object oriented style

SYNOPSIS
public DateInterval DateTime::diff (DateTimeInterface $datetime2, [bool $absolute = false]) DESCRIPTION
DateInterval DateTimeImmutable::diff (DateTimeInterface $datetime2, [bool $absolute = false]) DateInterval DateTimeInterface::diff (Date- TimeInterface $datetime2, [bool $absolute = false]) Procedural style DateInterval date_diff (DateTimeInterface $datetime1, DateTimeInterface $datetime2, [bool $absolute = false]) Returns the difference between two DateTimeInterface objects. PARAMETERS
o $datetime - The date to compare to. o $absolute - Should the interval be forced to be positive? RETURN VALUES
The DateInterval object representing the difference between the two dates or FALSE on failure. EXAMPLES
Example #1 DateTime.diff(3) example Object oriented style <?php $datetime1 = new DateTime('2009-10-11'); $datetime2 = new DateTime('2009-10-13'); $interval = $datetime1->diff($datetime2); echo $interval->format('%R%a days'); ?> Procedural style <?php $datetime1 = date_create('2009-10-11'); $datetime2 = date_create('2009-10-13'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%R%a days'); ?> The above examples will output: +2 days Example #2 DateTime object comparison Note As of PHP 5.2.2, DateTime objects can be compared using comparison operators. <?php $date1 = new DateTime("now"); $date2 = new DateTime("tomorrow"); var_dump($date1 == $date2); var_dump($date1 < $date2); var_dump($date1 > $date2); ?> The above example will output: bool(false) bool(true) bool(false) SEE ALSO
DateInterval.format(3), DateTime.add(3), DateTime.sub(3). PHP Documentation Group DATETIME.DIFF(3)
Man Page