date_interval_create_from_date_string


php apg

SETS UP a DateInterval from the relative parts of the STRING.

This function is an alias of DateInterval::createFromDateString.



<?php

/* - - - - - - - - - - - - - - - - -

       Object oriented style 
   
   - - - - - - - - - - - - - - - - - */

DateInterval|false public static DateInterval::createFromDateString str $datetime )


where,

$datetime A date with relative parts
                   
Specificallythe 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
                   
Specificallythe relative formats supported by the parser 
                   used 
for strtotime
                   
and DateTime will be used to construct 
                   the DateInterval  

?>

 $datetime 


A date with relative parts.

Specifically, the relative formats supported by the parser used for the function strtotime and DateTime will be used to construct the DateInterval.



  1 EXERCISE   

<?php

$date 
date_create('now');

date_add($datedate_interval_create_from_date_string('-1 year 35 days'));

echo 
date_format($date'Y-m-d');

?>

  2 EXERCISE   

<?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>";  

?>

  3 EXERCISE   

<?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');

?>