Search code examples
sql-servertimeutc

How to convert from UTC to EST in SQL?


I am currently using:

sample_start_time AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time' AS sample_start_time_est

from: Convert Datetime column from UTC to local time in select statement

sample_start_time
2021-03-10 21:13:00.000

becomes

sample_start_time_est
2021-03-10 16:13:00.000 -05:00

Though EST is now displayed, I think the system still recognizes it as UTC based on the results of subsequent queries. How do I get the system to recognize the adjusted time as EST?

For instance:

sample_start_time_est = 2021-03-10 16:14:00.000 -05:00
end_time = 2021-03-10 18:14:00.000
WHERE sample_start_time_est < end_time

above WHERE clause currently evaluates to FALSE but I want it to be TRUE

I am using Microsoft SQL Server Management Studio.


Solution

  • CAST(sample_start_time AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time' AS DATETIME2) AS sample_start_time_est