Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Format Function In Sql in SQL

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:

DatabaseSupportsNotes
SQL ServerNumbers, Dates, CultureFull formatting options
MySQLNumbers onlyLimited date formatting support
MariaDBSimilar to MySQL

If you want, I can help you format specific data (dates, currencies) for your SQL dialect!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql