date_parse


php apg

RETURNS an associative ARRAY with detailed info about given date.



<?php

arr date_parse 
str $datetime )


where,

$datetime The date in format  accepted by the function strtotime

?>

 $datetime 


The date in format accepted by DateTimeImmutable::__construct.





This function returns an ARRAY with information about the parsed date on SUCCESS, FALSE on failure.

In case the date format has an error, the element ERRORS will contains the error messages.



  1 EXERCISE   

<?php

$date01 
'Feb 13,1980 11:32:30';

$dparsed01 date_parse($date01);

/*
echo '<pre>';
var_dump($dparsed01);
echo '</pre>';
*/

foreach($dparsed01 as $dpa01 => $dp01)
{
    
print_r($dpa01);
     echo 
'&nbsp;=&nbsp;';
    
print_r($dp01);
     echo 
'<br>';
}

?>

  2 EXERCISE   

<?php

$dt02 
"2019-01-24 16:58:00";

$dtp02 date_parse($dt02);

echo 
'<pre>';
print_r($dtp02);
echo 
'</pre>';

?>

  3 EXERCISE   

<?php

$dt03 
strtotime("now");

echo 
$dt03 '<br>';

setlocale(LC_ALL"en_US""american"
                      
"american english"
                      
"american-english"
                      
"english-american"
                      
"english-us"
                      
"english-usa"
                      
"enu""us""usa");

$trcnf03 "%G-%B-%d %H:%M:%S";

$stftm03 strftime($trcnf03$dt03);
echo 
$stftm03 '<pre>'

print_r(date_parse($stftm03));

echo 
'</pre>';

?>

  4 EXERCISE   

<?php

$dt04 
strtotime("last sunday");

echo 
$dt04 '<br>';

setlocale(LC_ALL"pt_BR.utf-8""portuguese-brazil""ptb");

$trcnf04 "%G-%B-%d %H:%M:%S";

$stftm04 strftime($trcnf04$dt04);
echo 
$stftm04 '<pre>'

print_r(date_parse($stftm04));

echo 
'</pre>';

?>

  5 EXERCISE   

<?php

$dt05 
strtotime("last sunday");

echo 
$dt05 '<br>';

setlocale(LC_ALL"en_US""american"
                      
"american english"
                      
"american-english"
                      
"english-american"
                      
"english-us"
                      
"english-usa"
                      
"enu""us""usa");

$trcnf05 "%G-%B-%d %H:%M:%S";

$stftm05 strftime($trcnf05$dt05);
echo 
$stftm05 '<pre>'

print_r(date_parse($stftm05));

echo 
'</pre>';

?>

  6 EXERCISE   

<?php

date_default_timezone_set
('UTC');

echo 
"<br><br><br><pre>";
var_dump(date_parse("2006-12-12 10:00:00.5"));
echo 
"<br><br>";
var_dump(date_parse("2006-12-12"));
echo 
"<br><br>";
var_dump(date_parse("2006-12--12"));
echo 
"<br><br>";
var_dump(date_parse("2006-02-30"));
echo 
"<br><br>";
var_dump(date_parse("2006-03-04"));
echo 
"<br><br>";
var_dump(date_parse("2006-03"));
echo 
"<br><br>";
var_dump(date_parse("03-03"));
echo 
"<br><br>";
var_dump(date_parse("0-0"));
echo 
"<br><br>";
var_dump(date_parse(""));
echo 
'</pre>';

?>

  7 EXERCISE   

<?php

//Set the default time zone
date_default_timezone_set("Europe/London");

echo 
"Testing date_parse() : error conditions.<br><br><br>";

echo 
"Testing date_parse() function with 
               unexpected characters in \$date argument:<br><br>"
;
$invalid_date "2OO9-02--27 10:00?00.5";

echo 
'<pre>';
var_dumpdate_parse($invalid_date) );
echo 
'</pre>';

?>