GET_FORMAT() function in MySQL
Last Updated :
10 Dec, 2020
GET_FORMAT() :
This function in MySQL helps to convert date or time or DateTime in a formatted string for the specified arguments. The GET_FORMAT() function is more useful if it is used in combination with DATE_FORMAT() function.
Syntax :
GET_FORMAT({DATE | TIME | DATETIME},
{'EUR' | 'USA' | 'JIS' | 'ISO' | 'INTERNAL'})
Parameters :
-
DATE | TIME | DATETIME - A date or time or DateTime.
- 'EUR' | 'USA' | 'JIS' | 'ISO' | 'INTERNAL' - Different formats used.
Returns :
The function will return a formatted string for the specified arguments.
Example-1 :
Basic usage of GET_FORMAT() function.
SELECT GET_FORMAT(DATE, 'EUR')
As New_Format;
Output :
Example-2 :
Now using DATE_FORMAT() function along with GET_FORMAT().
SELECT DATE_FORMAT('2020-12-25', GET_FORMAT(DATE, 'USA'))
AS 'New_Format';
Output :
Example-3 :
Usage of GET_FORMAT() function with Date values, which means the first argument is fixed as DATE and the second argument is changed continuously.
SELECT
GET_FORMAT(DATE, 'USA') AS 'USA_format',
GET_FORMAT(DATE, 'JIS') AS 'JIS_format',
GET_FORMAT(DATE, 'ISO') AS 'ISO_format',
GET_FORMAT(DATE, 'EUR') AS 'EUR_format';
Output :
USA_format | JIS_format | ISO_format | EUR_format |
---|
'%m.%d.%Y' | '%Y-%m-%d' | '%Y-%m-%d' | '%d.%m.%Y' |
Example-4 :
Usage of GET_FORMAT() function with DateTime values, which means the first argument is fixed as DATETIME and the second argument is changed continuously.
SELECT
GET_FORMAT(DATETIME, 'USA') AS 'USA_format',
GET_FORMAT(DATETIME, 'JIS') AS 'JIS_format',
GET_FORMAT(DATETIME, 'ISO') AS 'ISO_format',
GET_FORMAT(DATETIME, 'EUR') AS 'EUR_format';
Output :
USA_format | JIS_format | ISO_format | EUR_format |
---|
'%Y-%m-%d %H.%i.%s' | '%Y-%m-%d %H:%i:%s' | '%Y-%m-%d %H:%i:%s' | '%Y-%m-%d %H.%i.%s' |
Example-5 :
Usage of GET_FORMAT() function with Time values, which means the first argument is fixed as TIME and the second argument is changed continuously.
SELECT
GET_FORMAT(TIME, 'USA') AS 'USA_format',
GET_FORMAT(TIME, 'JIS') AS 'JIS_format',
GET_FORMAT(TIME, 'ISO') AS 'ISO_format',
GET_FORMAT(TIME, 'EUR') AS 'EUR_format';
Output :
USA_format | JIS_format | ISO_format | EUR_format |
---|
'%h:%i:%s %p' | '%H:%i:%s' | '%H:%i:%s' | '%H.%i.%s' |
Similar Reads
COT() Function in MySQL COT() function : This function in MySQL is used to return the cotangent of a specified number. If the specified number is 0, an error or NULL will be returned. In a right triangle, the cotangent of an angle is the length of it's adjacent side divided by the length of the opposite side. Similarly, th
1 min read
CONCAT() function in MySQL CONCAT() function in MySQL is used to concatenating the given arguments. It may have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. If a numeric argument is given then it is
2 min read
EXTRACT() Function in MySQL The EXTRACT() function in MySQL is a versatile tool used for retrieving specific components of date Whether we need the year, month, day or even the hour or minute. This function simplifies date manipulation and makes queries involving date and time data more efficient and easier to understand. In t
3 min read
CURDATE() Function in MySQL The CURDATE() function in MYSQL is used to return the current date. The date is returned to the format of "YYYY-MM-DD" (string) or as YYYYMMDD (numeric). This function equals the CURRENT_DATE() function. In this article, we are going to discuss about CURDATE() function in detail. Syntax CURDATE(); P
2 min read
MySQL DATE_FORMAT() Function MySQL DATE_FORMAT() function formats a specified date to a given format value. DATE_FORMAT() Function in MySQLThe DATE_FORMAT() function in MySQL formats a specified date or datetime according to the given format. The DATE_FORMAT() function allows you to customize the display of date and time values
3 min read
SQL Server FORMAT() Function SQL Server FORMAT() function formats the specified value in the given format. FORMAT Function in SQL ServerThe FORMAT function in SQL Server is used to format date/time and number values with locale-aware formatting. The FORMAT function achieves various formatting requirements, showing dates in spe
2 min read
ELT() Function in MySQL In this article, we are going to cover ELT function with examples. In ELT function, number field will state that how many strings will be there. ELT function in MySQL is used to returns the string which is at index number specified in the argument list. In this function there is number field and str
1 min read
DAY() Function in MySQL DAY() function : This function in MySQL is used to return the day of the month for a specified date (a number from 1 to 31). This function equals the DAYOFMONTH() function. Syntax : DAY(date) Parameter : This method accepts a parameter which is illustrated below : date : Specified date to extract th
1 min read
HEX() function in MySQL HEX() : This function in MySQL is used to return an equivalent hexadecimal string value of a string or numeric Input. If the input is a string then each byte of each character in the string is converted to two hexadecimal digits. This function also returns a hexadecimal string representation of the
2 min read
Node.js MySQL FORMAT() Function FORMAT() function is a built-in function in MySQL that is used to format input numbers in the format of ...**, ***, *** also, round float numbers to a specific number of decimal places. Syntax: FORMAT(number, number_of_decimal_places)Parameters: It takes two parameters as follows: number: The number
2 min read