Format Function In Sql in SQL
? FORMAT() Function in SQL
The FORMAT() function formats a number or date/time value according to a specified format or locale, returning a string.
? Syntax:
FORMAT(value, format [, culture])value: The number or date/time to format.
format: A format string (depends on the data type).
culture (optional): Specifies the locale (e.g.,
'en-US','de-DE').
? Supported In:
MySQL (mainly for numbers, limited date formatting)
SQL Server (rich support for numbers and dates)
MariaDB
? Examples in SQL Server:
Formatting Numbers:
SELECT FORMAT(12345.6789, 'N2'); -- '12,345.68' (number with 2 decimals)SELECT FORMAT(12345.6789, 'C'); -- '$12,345.68' (currency format)Formatting Dates:
SELECT FORMAT(GETDATE(), 'dd-MM-yyyy'); -- '06-06-2025'SELECT FORMAT(GETDATE(), 'MMMM dd, yyyy'); -- 'June 06, 2025'Using Culture:
SELECT FORMAT(12345.6789, 'C', 'fr-FR'); -- '12 345,68 €'? Example in MySQL (numbers only):
SELECT FORMAT(1234567.8910, 2); -- '1,234,567.89'Note: MySQL’s FORMAT() only formats numbers and uses the current locale for thousands separator.
? Summary:
| Database | Supports | Notes |
|---|---|---|
| SQL Server | Numbers, Dates, Culture | Full formatting options |
| MySQL | Numbers only | Limited date formatting support |
| MariaDB | Similar to MySQL |
If you want, I can help you format specific data (dates, currencies) for your SQL dialect!