- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements