SQL Server FORMAT() Function
Last Updated :
07 Jun, 2024
SQL Server FORMAT() function formats the specified value in the given format.
FORMAT Function in SQL Server
The 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 specific formats or formatting numeric values.
Syntax
SQL Server FORMAT() function syntax is:
FORMAT(value, format, culture)
Parameter:
FORMAT function accepts three parameters described below:
- Value: It is the value to do formatting. It should be in support of the data type format.
- Format: It is the required format in which we require the output.
- Culture: It is an optional parameter. By default, SQL Server uses the current session language for a default culture. We can provide a specific culture here, but the .Net framework should support it. We get an error message in case of invalid Culture
SQL Server FORMAT Function Example
Let's look at some examples of the FORMAT function in SQL Server. Learning SQL Server FORMAT() function with examples help in understanding the concept better.
Using FORMAT function to format a number example
In this example, we will format a number using FORMAT function.
Query:
SELECT FORMAT(25, 'N')
Output:

Format in percentage using FORMAT function example
In this example, we will format a value to PERCENTAGE format.
Query:
SELECT FORMAT(1, 'P', 'en-US')AS [PERCENTAGE IN US FORMAT],
FORMAT(1, 'P', 'en-IN') AS [PERCENTAGE IN INDIA FORMAT];
Output:

Format in Date using FORMAT function example
In this example, we will format the date in the desired format.
Query:
DECLARE @d DATETIME = GETDATE();
SELECT FORMAT( @d, 'dd/MM/yyyy', 'en-US' ) AS 'DateTime Result'
Output:

Format time in AM or PM format using FORMAT function example
In this example, we will format the current time with AM or PM.
Query:
SELECT FORMAT(SYSDATETIME(), N'hh:mm tt');
Output:

Format currency using FORMAT function example
In this example, we change the CURRENCY format.
Query:
SELECT
FORMAT(1, 'C', 'in-IN') AS 'INDIA',
FORMAT(1, 'C', 'ch-CH') AS 'CHINA',
FORMAT(1, 'C', 'sw-SW') AS 'SWITZERLAND',
FORMAT(1, 'C', 'us-US') AS 'USA';
Output:

Similar Reads
DAY() Function in SQL Server DAY() function : This function in SQL Server is used to return the day of the month i.e, from 1st to 31st for date stated. Features : This function is used to find the day of the month for a date specified. This function comes under Date Functions. This function accepts only one parameter i.e, date.
2 min read
CONCAT_WS() Function in SQL Server CONCAT_WS() : This function concatenates two or more strings together with a separator. Syntax : CONCAT_WS(separator, input_string1, input_string2, [...input_stringN]); Parameter : This method accepts two-parameters as mentioned above and described below as follows. separator - It is an expression o
1 min read
GET_FORMAT() function in MySQL 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' |
2 min read
SQL Server LEN() Function SQL SERVER LEN() function calculates the number of characters of an input string, excluding the trailing spaces. LEN() Function in SQL ServerThe LEN function in the SQL Server fetches the number of characters in a string. It counts the preceding spaces but not the trailing spaces. For eg, 'SQL SERVE
2 min read
DATENAME() Function in SQL Server DATENAME() function : This function in SQL Server is used to find a given part of the specified date. Moreover, it returns the output value as a string. Features : This function is used to find a given part of the specified date.This function comes under Date Functions.This function accepts two para
2 min read
DATEPART() Function in SQL Server DATEPART() function :This function in SQL Server is used to find a given part of the specified date. Moreover, it returns the output value as an integer.Features : This function is used to find a given part of the specified date.This function comes under Date Functions.This function accepts two para
2 min read
SQL Server TRIM() Function The SQL Server TRIM() function omits the space character or additional stated characters from the beginning or the end of a specified string. TRIM in SQL ServerThe TRIM function in SQL Server is used to remove leading and trailing spaces from a string. Itâs particularly useful for manipulating and c
2 min read
SQL Server SPACE() function The SQL Server SPACE() function is a handy tool for generating a string of space characters. It is particularly useful for formatting and padding data within SQL queries. By specifying the number of spaces, users can ensure consistent spacing in output results, which can be critical for aligning tex
3 min read
SQL Server ROUND() Function The SQL Server ROUND() function rounds off a specified number to a decimal place. If the length is negative and larger than the number of digits before the decimal point, ROUND returns 0. ROUND in SQL ServerThe ROUND() function in SQL Server rounds off a number to a specified decimal place. It accep
2 min read
SQL Server | STUFF() Function The STUFF() function in SQL Server is a powerful string manipulation tool used to delete a specified length of characters from a string and insert another set of characters at a given starting position. This function becomes particularly useful in scenarios where complex string operations are requir
2 min read