Friday, January 30, 2026
HomeLanguagesPHP | IntlDateFormatter getErrorCode() Function,

PHP | IntlDateFormatter getErrorCode() Function,

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

Syntax:

  • 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:

Program:




<?php
  
// Create a date formatter
$formatter = datefmt_create(
    'en_US',
    IntlDateFormatter::SHORT,
    IntlDateFormatter::SHORT,
    'Asia/Kolkata',
    IntlDateFormatter::GREGORIAN
);
  
// 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: " . 
        datefmt_get_error_message($formatter);
}
  
echo "\n\n";
  
// Format the date/time value
// as a string
$str = $formatter->format("neveropen");
  
if (!$str) {
    echo "Error code: " . 
        $formatter->getErrorCode() . "\n";
      
    echo "Error message: " . 
        $formatter->getErrorMessage();
}
  
?>


Error:

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

Output:

Error code: 0
Error message: U_ZERO_ERROR

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

Reference: https://www.php.net/manual/en/intldateformatter.geterrorcode.php

RELATED ARTICLES

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6917 POSTS0 COMMENTS