SQL FORMAT

The FORMAT function is used to specify a field as displayed in the query result.

SQL Syntax FORMAT

SELECT FORMAT(column, format) FROM table

Example SQL FORMAT

Given the following table 'products'

idproductprice
1computer1200.25
2printer65.57
3keyboard10.84

If we know the prices of the products to date, but we want the date is formatted 'YYYY-MM-DD'.

SELECT product, price, FORMAT(NOW(), ‘YYYY-MM-DD’) AS date FROM products

The result will be:

productpricedate
computer900.252012-02-10
printer65.572012-02-10
keyboard10.842012-02-10