<?php
/* - - - - - - - - - - - - - - - - -
Object oriented style
- - - - - - - - - - - - - - - - - */
DateInterval|false public static DateInterval::createFromDateString ( str $datetime )
where,
$datetime = A date with relative parts.
Specifically, the relative formats supported by the parser
used for strtotime
and DateTime will be used to construct
the DateInterval
?>
<?php
/* - - - - - - - - - - - - - - - - -
Procedural style
- - - - - - - - - - - - - - - - - */
date_interval_create_from_date_string ( $datetime )
where,
$datetime = A date with relative parts.
Specifically, the relative formats supported by the parser
used for strtotime
and DateTime will be used to construct
the DateInterval
?>
<?php
$date = date_create('now');
date_add($date, date_interval_create_from_date_string('-1 year 35 days'));
echo date_format($date, 'Y-m-d');
?>
<?php
$datetime = "3year + 3months + 26 day + 12 hours+ 30 minutes +23 seconds";
$obj02 = date_interval_create_from_date_string($datetime);
foreach($obj02 as $k02 => $v02)
echo "$k02 => $v02 <br>";
?>
<?php
function dateintr($var03a, $var03b)
{
print_r (new DateInterval($var03a));
echo "<br><br>";
print_r (DateInterval::createFromDateString($var03b));
echo "<br><br><br><br>";
}
dateintr('P12D', '12 days');
dateintr('P7M', '7 months');
dateintr('P12Y', '12 years');
dateintr('PT9H', '9 hours');
dateintr('PT19M', '19 minutes');
dateintr('PT45S', '45 seconds');
?>