'Convert a text column to a datetime column
How do I convert a column of type text to type date/time? I have the createdon column that I convert from UTC time to eastern time zone with day light savings time in consideration. This works. However, the createon column results in a type text. I need it in date and time.
Below is my SQL query. How exactly would you write the conversion within the existing query? This is for SQL Server. Thanks.
select [$Table].[field1] as [field1],
...,
[$Table].[createdon] at time zone 'UTC' at time zone 'Eastern Standard Time' as [createdon],
...,
[$Table].[fieldN] as [fieldN]
from [dbo].[TableA] as [$Table]
Solution 1:[1]
I was able to do the conversion by using the cast keyword and convert as a date type.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | superx |
