Thursday, December 11, 2025
HomeLanguagesPHP | date_get_last_errors() Function

PHP | date_get_last_errors() Function

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:

  • Procedural style:
    array date_get_last_errors( void )
  • Object oriented style:
    array DateTime::getLastErrors( void )

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) {
      
    // For demonstration purposes only...
    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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32440 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6811 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12023 POSTS0 COMMENTS
Shaida Kate Naidoo
6942 POSTS0 COMMENTS
Ted Musemwa
7193 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS