SQL FORMAT() Function

FORMAT() Function

The FORMAT function is used to format the display of fields.

SQL FORMAT() Syntax

SELECT FORMAT(column_name,format) FROM table_name
Parameter Description
column_name Required. The field to be formatted.
format Required. Specify the format.

SQL FORMAT() Example

We have the following "Products" table:

Prod_Id ProductName Unit UnitPrice
1 gold 1000 g 32.35
2 silver 1000 g 11.56
3 copper 1000 g 6.85

Now, we want to display the name and price corresponding to each date (the display format of the date is "YYYY-MM-DD").

We use the following SQL statement:

SELECT ProductName, UnitPrice, FORMAT(Now(),'YYYY-MM-DD') as PerDate
FROM Products

The result set is similar to this:

ProductName UnitPrice PerDate
gold 32.35 12/29/2008
silver 11.56 12/29/2008
copper 6.85 12/29/2008