I would like to convert getdate()
in SQL Server to EST time.

- 98,240
- 88
- 296
- 433

- 201
- 1
- 2
- 3
-
1Would it be more correct to say you are looking for eastern time: I.E. what is on the clock on the east coast where people observe daylight savings time? – Empiricist Jun 19 '17 at 15:47
-
These all are wrong answers EST to UTC is not always 5 hours difference.It depends on Day time saving It can be 4 hours or 5 hours. http://ww2010.atmos.uiuc.edu/(Gh)/guides/maps/utc/frutc.rxml – Jin Thakur Nov 08 '16 at 20:17
11 Answers
UPDATED ANSWER (05-29-2020)
The Azure SQL team has released a new function which makes this even easier. SELECT CURRENT_TIMEZONE_ID()
will return your server's timezone. Adding this function into the ORIGINAL ANSWER below yields a single query will work globally on all Azure SQL Servers.
SELECT CONVERT(DATETIME,GETDATE() AT TIME ZONE (SELECT CURRENT_TIMEZONE_ID()) AT TIME ZONE 'Eastern Standard Time')
This query will work on any Azure SQL Server.
ORIGINAL ANSWER:
There are a lot of answers here that are unnecessarily complex, or that don't account for daylight savings time. No massive CASE
statements needed. No new stored procedure, or scalar/user defined functions are needed. As of SQL Server 2016, converting between timezones can be done with a single line of native sql. This has advantages. For example, it can be called from reports or used on databases that are read-only.
SELECT CONVERT(DATETIME,GETDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time')
That's it. Above, we are using the AT TIME ZONE
features, described in more detail here. There may be some functions and features that are new here, so an explanation is warranted. The query above calls GETDATE()
and sets it's timezone as UTC using AT TIMEZONE
. Implicitly, this is also changing it's datatype from a datetime
to datetimeoffset
. Next, we'll call AT TIMEZONE
again to cut it over to EST. Lastly, we'll wrap the entire thing in CONVERT()
to get it back to a datetime
, dropping the unneeded +/- hours portion during the process.
Taking the query step-by-step ...
SELECT [GetDate] = GETDATE()
SELECT [GetDateAtUtc] = GETDATE() AT TIME ZONE 'UTC'
SELECT [GetDateAtUtcAtEst] = GETDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time'
SELECT [GetDateEst] = CONVERT(DATETIME,GETDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time')

- 2,498
- 2
- 28
- 37
-
1Updated, well explained, well demonstrated... I like everything about this answer. – laancelot Jun 16 '20 at 14:14
-
1The GetDateEst (4th line down) just saved me from writing a messy function to change '-5:00' into '-5' for purposes of use in a DATEADD function. Here's an upvote! ⬆ – JayTee Dec 15 '21 at 18:00
Have you considered GETUTCDATE() and performing the offset from there? If you mean EST as in standard time, then that is UTC-5, so
select dateadd(hour,-5,GETUTCDATE())

- 105,798
- 26
- 196
- 262
-
12
-
8@AndroidDebaser You don't need to account for day light saving time. EST will always be UTC-5. Places that observer day light saving time will switch to EDT and the OP asked for EST specifically. So this answer is correct. – solartic May 25 '15 at 16:31
-
5@Solartic Sure, this answer is _technically_ correct because EST is canoncially *always* five out from UTC. However, the OP most likely wants a forumula that works year round. I say fair, because folks call it EST year round. There is no entry for EDT `sys.time_zone_info` table. So while this answer is _technically_ correct, I think It's fair to presume the OP wants something that accepts a UTC date and translate it correctly to their current eastern time, whether recgonizing daylight savings or not. For that reason, I believe the other answers here are more *useful*. Thanks. – Troy Witthoeft Apr 10 '20 at 18:00
-
@troy-witthoeft I do think it is fair to take it into consideration that the OP might want Eastern Time Zone (ET) instead of EST. But not fair to assume they don't specifically need EST. I think this is a good answer for what was asked. Is it really what the OP wants? Maybe not. And that's the value of having other answers. Together they all add value. Some short, simple and to the point and some with useful potential considerations. Thanks for your response. – solartic Jun 19 '20 at 20:48
EST is GMT-5 hours while EDT is GMT-4 hours.
To get EST:
select dateadd(hour,-5,GETUTCDATE())
To get EDT :
select dateadd(hour,-4,GETUTCDATE())
-
That is subject to change. There is nothing requiring the offset to be constant. – Ross Bush Sep 19 '18 at 18:05
SQL server itself has the table current_utc_offset
with correct offset for summer and winter time.
Please, try the query select * from current_utc_offset
, change the date to different season on your server and review the table again.
So the correct function to get EST would be:
CREATE FUNCTION [dbo].[Getestlocaldatetime] ()
returns DATETIME
AS
BEGIN
DECLARE @zz NVARCHAR(12);
DECLARE @hh NVARCHAR(3);
DECLARE @dd DATETIME;
SET @zz = (SELECT current_utc_offset
FROM sys.time_zone_info
WHERE NAME = N'US Eastern Standard Time')
SET @hh = Substring(@zz, 1, 3);
SET @dd = Dateadd(hh, CONVERT(INT, @hh), Getutcdate())
RETURN @dd
END

- 21,981
- 30
- 95
- 142

- 89
- 3
-
These are the same values that are contained in time zone info registry keys which is what windows uses to keep itself in sync. This is the best answer for SQL Server 2014 and up. – Ross Bush Sep 19 '18 at 18:09
-
I think it might be best for 2014, but not 2016 and up. SQL 2016 introuduced the `AT TIME ZONE` [feature](https://sqlperformance.com/2016/07/sql-plan/at-time-zone) which simplifies this. That feature is also using the `sys.time_zone_info` table. – Troy Witthoeft Apr 10 '20 at 16:42
SELECT CONVERT(VARCHAR, CONVERT(DATETIME, GETDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time'), 100) AS [Date_Result]

- 1,467
- 15
- 31
GetDate()
is the system time from the server itself.
Take the hour difference of the GetDate()
now and the time it is now in EST use this code where 1 is that said difference ( in this instance the server is in Central Time zone) (This is also assuming your server is accounting for DST)
SELECT Dateadd(hour, 1, Getdate()) AS EST

- 21,981
- 30
- 95
- 142

- 369
- 3
- 5
If you are attempting to output a local time, such as eastern time, with Daylight savings time, you need a function that Detects the start and end of daylight savings time and then applies a variable offset: I've found this: http://joeyiodice.com/convert-sql-azure-getdate-utc-time-to-local-time/ useful.

- 116
- 2
- 8
For those who are using latest version of sql server can create a .net function
A scalar-valued function (SVF) returns a single value, such as a string, integer, or bit value. You can create scalar-valued user-defined functions in managed code using any .NET Framework programming language. These functions are accessible to Transact-SQL or other managed code. For information about the advantages of CLR integration and choosing between managed code and Transact-SQL.
Since .NET has access to all time zone at operating system so you don't have to calculate daylight saving -4 or -5 fundamentals.
var timeUtc = DateTime.UtcNow;
TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime easternTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, easternZone);

- 2,711
- 18
- 15
Select CONVERT(DATETIME,GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time')

- 11
- 1
-
I think this is the most eloquent, I discovered you need to get the UTC at timezone UTC before you convert to Eastern Standard Time, otherwise you will get thrown off by whatever the server timezone is. – Robert Sawyer Apr 12 '20 at 20:13
-
Very nice. Note that you can edit your answers so next time you do not have to comment on it. – Simon.S.A. Apr 12 '20 at 22:12
using GETDATE() :
GMT :
DATE WILL BE DISPLAYED:
SELECT GETDATE()
EST :
USE GETDATE() FOR CONVERSION NOW:
SELECT DATEADD(HOUR, -4, CONVERT(varchar(20),GETDATE(),120))

- 3,830
- 26
- 30
If you want to do this without calling a function, you can do it with a CASE statement as well. The code below converts a UTC field to Mountain Time accounting for daylight savings. For EST, you would just change all the -6 to -4 and change all the -7 to -5.
--Adjust a UTC value, in the example the UTC field is identified as UTC.Field, to account for daylight savings time when converting out of UTC to Mountain time.
CASE
--When it's between March and November, it is summer time which is -6 from UTC
WHEN MONTH ( UTC.Field ) > 3 AND MONTH ( UTC.Field ) < 11
THEN DATEADD ( HOUR , -6 , UTC.Field )
--When its March and the day is greater than the 14, you know it's summer (-6)
WHEN MONTH ( UTC.Field ) = 3
AND DATEPART ( DAY , UTC.Field ) >= 14
THEN
--However, if UTC is before 9am on that Sunday, then it's before 2am Mountain which means it's still Winter daylight time.
CASE
WHEN DATEPART ( WEEKDAY , UTC.Field ) = 1
AND UTC.Field < '9:00'
--Before 2am mountain time so it's winter, -7 hours for Winter daylight time
THEN DATEADD ( HOUR , -7 , UTC.Field )
--Otherwise -6 because it'll be after 2am making it Summer daylight time
ELSE DATEADD ( HOUR , -6 , UTC.Field )
END
WHEN MONTH ( UTC.Field ) = 3
AND ( DATEPART ( WEEKDAY , UTC.Field ) + 7 ) <= DATEPART ( day , UTC.Field )
THEN
--According to the date, it's moved onto Summer daylight, but we need to account for the hours leading up to 2am if it's Sunday
CASE
WHEN DATEPART ( WEEKDAY , UTC.Field ) = 1
AND UTC.Field < '9:00'
--Before 9am UTC is before 2am Mountain so it's winter Daylight, -7 hours
THEN DATEADD ( HOUR , -7 , UTC.Field )
--Otherwise, it's summer daylight, -6 hours
ELSE DATEADD ( HOUR , -6 , UTC.Field )
END
--When it's November and the weekday is greater than the calendar date, it's still Summer so -6 from the time
WHEN MONTH ( UTC.Field ) = 11
AND DATEPART ( WEEKDAY , UTC.Field ) > DATEPART ( DAY , UTC.Field )
THEN DATEADD ( HOUR , -6 , UTC.Field )
WHEN MONTH ( UTC.Field ) = 11
AND DATEPART ( WEEKDAY , UTC.Field ) <= DATEPART ( DAY , UTC.Field )
--If the weekday is less than or equal to the calendar day it's Winter daylight but we need to account for the hours leading up to 2am.
CASE
WHEN DATEPART ( WEEKDAY , UTC.Field ) = 1
AND UTC.Field < '8:00'
--If it's before 8am UTC and it's Sunday in the logic outlined, then it's still Summer daylight, -6 hours
THEN DATEADD ( HOUR , -6 , UTC.Field )
--Otherwise, adjust for Winter daylight at -7
ELSE DATEADD ( HOUR , -7 , UTC.Field )
END
--If the date doesn't fall into any of the above logic, it's Winter daylight, -7
ELSE
DATEADD ( HOUR , -7 , UTC.Field )
END

- 37
- 9