What is the use of MySQL GET_FORMAT() function?


MySQL GET_FORMAT() function is used to convert a datatype like DATE, TIME, DATETIME or TIMESTAMP in a formatted manner based on the standard format given as the second argument. The standard format type may be EUR, INTERNAL, ISO, JIS or USA. The format codes returned are the same codes used by the DATE_FORMAT() function. This function is useful in combination with DATE_FORMAT() and STR_TO_DATE() function.

Syntax

GET_FORMAT(data_type, standard_format)

Here as we told earlier, data_type would be DATE, TIME, DATETIME or TIMESTAMP, and standard_format maybe EUR, INTERNAL, ISO, JIS or USA.

Example

mysql> Select GET_FORMAT(DATE, 'USA') AS 'AMERICAN Format',
-> GET_FORMAT(DATE, 'ISO') AS 'ISO Format';

+-----------------+------------+
| AMERICAN Format | ISO Format |
+-----------------+------------+
| %m.%d.%Y | %Y-%m-%d          |
+-----------------+------------+
1 row in set (0.00 sec)

The query above returns the date format used in USA and ISO Date format.

mysql> Select GET_FORMAT(TIME, 'USA') AS 'AMERICAN Format',
-> GET_FORMAT(TIME, 'ISO') AS 'ISO Format';

+-----------------+------------+
| AMERICAN Format | ISO Format |
+-----------------+------------+
| %h:%i:%s %p | %H:%i:%s       |
+-----------------+------------+
1 row in set (0.00 sec)

The query above returns the time format used in USA and ISO Date format.

Updated on: 20-Jun-2020

105 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements