Convert YYYYMMDD to DateTime,Convert YYYYMMDD to DateTime Format,SQL,SQL Query
The following SQL query converts the date stored as decimal or numeric in the form of YYYYMMDD to datetime.
1) SELECT CAST(CAST(YourDateField AS VARCHAR(8)) AS DATETIME)
For example:
SELECT CAST(CAST(20060204 AS VARCHAR(8)) AS DATETIME) AS [DateTime]
will be displayed as
2006-02-04 00:00:00.000
2) CONVERT(datetime, YourDateField) AS [DateTime]
For example:
CONVERT(datetime, '20060204') AS [DateTime]
will be displayed as
02/04/2006
No comments:
Post a Comment