In SQL, FORMAT() function is used to format a column value means how a field will to be displayed.
FORMAT() Syntax
SELECT FORMAT(column_name,format) FROM table_name;
In the above syntax parameters are as below:
Parameter Description
column_name Required. The field needs to be formatted.
format Required. Specifies the format for specified column.
We have a table "employee" as below:
employee
id first_name last_name salary
.......................................................
1 John Simp 10000
2 Chris Hely 25000
3 Joy Roy 20000
4 Jenny Mill 35000
FORMAT() Example
The below query selects the first_name and salary for today (formatted like YYYY-MM-DD) from the "employee" table:
SELECT first_name, salary, FORMAT(NOW(), 'YYYY-MM-DD') as current_date FROM employee;
Result:
first_name salary current_date
.......................................................
John 10000 2016-01-01
Chris 25000 2016-01-01
Joy 20000 2016-01-01
Jenny 35000 2016-01-01
Hope this will help you :)
0 Comment(s)