Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PHP | IntlDateFormatter getErrorCode() Function,

  • Last Updated : 10 Oct, 2019

The IntlDateFormatter::getErrorCode() function is an inbuilt function in PHP which is used to return the error code from last operation.


  • Object-oriented style:
    int IntlDateFormatter::getErrorCode( void )
  • Procedural style:
    int datefmt_get_error_code( IntlDateFormatter $fmt )

Parameters: This function uses a single parameter $fmt which holds the resource of formatter.

Return Value: This function returns the error code, one of UErrorCode values. Initial value is U_ZERO_ERROR.

Below program illustrates the IntlDateFormatter::getErrorCode() function in PHP:


// Create a date formatter
$formatter = datefmt_create(
// Format the date/time value
// as a string
$str = datefmt_format($formatter);
if (!$str) {
    echo "Error code: "
        datefmt_get_error_code($formatter) . "\n";
    echo "Error message: "
echo "\n\n";
// Format the date/time value
// as a string
$str = $formatter->format("geeks");
if (!$str) {
    echo "Error code: "
        $formatter->getErrorCode() . "\n";
    echo "Error message: "


PHP Warning:  datefmt_format() expects exactly 2 parameters, 1 given
in /home/700d8660f05cec95beb6e1ab21252ab1.php on line 14


Error code: 0
Error message: U_ZERO_ERROR

Error code: 1
Error message: datefmt_format: string 'geeks' is not numeric, which would
be required for it to be a valid date: U_ILLEGAL_ARGUMENT_ERROR


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!