Convert date format in sql
- how to format datetime in sql
- how to format datetime in sql server
- how to format datetime in sql query
- how to format datetime in oracle sql
Sql create table date format dd/mm/yyyy
Sql time format...
Problem
You’d like to display a date value in another format in SQL Server.
Example
Our database has a table named with data in the columns (primary key), , and .
| id | name | start_date |
|---|---|---|
| 1 | Lisa Bank | 2019-01-20 |
| 2 | Credit Financial Institute | 2018-03-14 |
| 3 | Williams Holding | 2019-10-28 |
For each company, let’s convert their start date to a new format, , where is a 4-digit year, is a 2-digit month, and is a 2-digit day.
Solution 1
We’ll use the function.
Here’s the query you’d write:
SELECT CONVERT(NVARCHAR, start_date, 111) AS new_date FROM company;Here is the result:
| name | start_date |
|---|---|
| Lisa Bank | 2019/01/20 |
| Credit Financial Institute | 2018/03/14 |
| Williams Holding | 2019/10/28 |
Discussion
Use the function to change the format of a date from a given column or expression.
This function takes three arguments:
- The new data type (in our example, ).
- An expression or column name containing the date to format (in our example, the column).
- An optional style code, as an integer.
(In our example, the style displays the date using slashes to separat
- how to change date time format in sql developer
- how to change datetime format in sql