Open In App

PHP | IntlDateFormatter getErrorCode() Function,

Last Updated : 10 Oct, 2019
Like Article

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


Similar Reads

PHP | IntlCalendar getErrorCode() Function
The IntlCalendar::getErrorCode() function is an inbuilt function in PHP which returns the numeric ICU error code for the last call on this object or the IntlCalendar given for the calendar parameter. This function can indicate a warning message (negative error code) or no error. Syntax: Object oriented style int IntlCalendar::getErrorCode( void ) P
1 min read
PHP | IntlDateFormatter getDateType() Function
The IntlDateFormatter::getDateType() function is an inbuilt function in PHP which is used to get the datetype used for the IntlDateFormatter object. Syntax: Object oriented style: int IntlDateFormatter::getDateType( void ) Procedural style: int datefmt_get_datetype( IntlDateFormatter $fmt ) Parameters: This function uses single parameter $fmt which
2 min read
PHP | IntlDateFormatter format() Function
The IntlDateFormatter::format() function is an inbuilt function in PHP which is used to format the date/time value as a string. Syntax: Object oriented style: string IntlDateFormatter::format( mixed $value ) Procedural style: string datefmt_format( IntlDateFormatter $fmt, mixed $value ) Parameters: This function uses two parameters as mentioned abo
2 min read
PHP | IntlDateFormatter formatObject() Function
The IntlDateFormatter::formatObject() function is an inbuilt function in PHP which is used to formats an IntlDateFormatter object. This function allows to format the IntlCalendar or DateTime object. Syntax: Object oriented style:string IntlDateFormatter::formatObject( object $object, mixed $format = NULL, string $locale = NULL )Procedural style:str
2 min read
PHP | IntlDateFormatter getCalendar() Function
The IntlDateFormatter::getCalendar() function is an inbuilt function in PHP which is used to return the calendar type used for the IntlDateFormatter object.Syntax: Object oriented style: int IntlDateFormatter::getCalendar( void )Procedural style: int datefmt_get_calendar( IntlDateFormatter $fmt ) Parameters: This function accepts single parameter $
2 min read
How to get the function name inside a function in PHP ?
To get the function name inside the PHP function we need to use Magic constants(__FUNCTION__). Magic constants: Magic constants are the predefined constants in PHP which is used on the basis of their use. These constants are starts and end with a double underscore (__). These constants are created by various extensions. Syntax: $string = __FUNCTION
1 min read
How the User-Defined Function differs from Built-in Function in PHP ?
In PHP, functions are blocks of reusable code that perform specific tasks. They enhance code readability, modularity, and maintainability by encapsulating logic into named units. PHP functions can be categorized into two main types: user-defined functions and built-in functions. User-Defined FunctionsUser-defined functions are functions created by
2 min read
PHP 5 vs PHP 7
PHP is a server side scripting language designed for web development by Rasmus Lerdorf in 1994. Since its launch in 1994 PHP has become an industry standard supporting almost 80% of the websites ( 79.8% to be precise) with its closest competitor being ASP.Net at 19.8% and others like Ruby, Java trailing far behind. The PHP development team released
4 min read
PHP | Get PHP configuration information using phpinfo()
PHP provides us with a built-in function phpinfo() which gives us the details about the PHP version and PHP configuration of PHP installed in our system. To know about the Configurations and PHP version which is installed in your computer, a simple PHP script can be used. The script consists of a PHP function called "phpinfo()" which outputs inform
2 min read
PHP | php.ini File Configuration
At the time of PHP installation, php.ini is a special file provided as a default configuration file. It's very essential configuration file which controls, what a user can or cannot do with the website. Each time PHP is initialized, the php.ini file is read by the system. Sometimes you need to change the behavior of PHP at runtime, then this config
5 min read