PHP | date_get_last_errors() Function
Last Updated :
14 Sep, 2018
The date_get_last_errors() function is an inbuilt function in PHP which is used to returns the warnings and errors. This function parse a date/time string and returns an array of warnings and errors.
Syntax:
Parameters: This function does not accept any parameter.
Return Value: This function returns an array containing information about warnings and errors.
Below programs illustrate the date_get_last_errors() function in PHP:
Program 1:
<?php
$date = date_create();
print_r(date_get_last_errors());
?>
|
Output:
Array
(
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 0
[errors] => Array
(
)
)
Program 2:
<?php
try {
$date = new DateTime( 'vgdgh' );
}
catch (Exception $e ) {
print_r(DateTime::getLastErrors());
}
?>
|
Output:
Array
(
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 1
[errors] => Array
(
[0] => The timezone could not be found in the database
)
)
Related Articles:
Reference: http://php.net/manual/en/datetime.getlasterrors.php
Share your thoughts in the comments
Please Login to comment...