Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • what is the use of FORMAT() function in SQL?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 95
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: