I want to convert the column (EXECUTION_LOCAL_DATE_TIME) which has datetime format as (YYYY-MM-DD hh:mm:ss.nnnnnnn) to format (YYYY-MM-DD). Ho do i get this. I am working on SQL server management studio
-
Select cast ('YYYY-MM-DD hh:mm:ss.nnnnnnn' as date) from tbl1 – Avi Jan 25 '19 at 01:42
-
convert(date,EXECUTION_LOCAL_DATE_TIME) – John Cappelletti Jan 25 '19 at 01:42
-
3Possible duplicate of [Convert Date format into DD/MMM/YYYY format in SQL Server](https://stackoverflow.com/questions/17205441/convert-date-format-into-dd-mmm-yyyy-format-in-sql-server) – GMB Jan 25 '19 at 01:45
5 Answers
If your intention is to just get the DATE part of a DATETIME then you can just convert the format to DATE (note that this will return a 'Date' datatype, not specifically formatted to a string 'YYYY-MM-DD'.)
eg:
DECLARE @Dt DATETIME = '2019-01-25T12:00:00'
SELECT CONVERT(DATE, @Dt)
Will return '2019-01-25'

- 944
- 7
- 16
Ideally you should return the datetime format from your query and let your presentation layer handle formatting.
However if you are using SQL server 2012 or higher then you can use the Format() function. See the below answer:

- 944
- 7
- 16
If you're using SQL Server 2012 or higher you can use the FORMAT() function.
In your case you'd need
SELECT FORMAT(EXECUTION_LOCAL_DATE_TIME, 'yyyy-MM-dd') FROM TABLE_NAME
You can find additional info here
https://www.mssqltips.com/sqlservertip/2655/format-sql-server-dates-with-format-function/ https://learn.microsoft.com/en-us/sql/t-sql/functions/format-transact-sql?view=sql-server-2017

- 694
- 5
- 7
Here Is the Code Worked For me
SELECT convert(varchar, EXECUTION_LOCAL_DATE_TIME, 111) from Tablename
The Execution_Local_Date_Time
will be Converted to yyyy/mm/dd
format.

- 5,547
- 8
- 20
- 42

- 31
- 4