Reputation: 39
Using AT TIME ZONE is there a way to get my UTC Time without the 00:00 AT The end without using a LEFT in my query.
im doing this:
SELECT GETDATE() AT TIME ZONE 'EASTERN standard time' at time zone 'UTC'
Answer: 2018-03-05 15:08:00.930 +00:00
and trying to see if there is a better way other than doing
SELECT LEFT(GETDATE() AT TIME ZONE 'EASTERN standard time' at time zone 'UTC',23)
Upvotes: 2
Views: 1722
Reputation: 1656
The following code will output your desired results:
CONVERT(VARCHAR, CONVERT(DATETIME, <DateField> AT TIME ZONE 'Eastern Standard Time' AT TIME ZONE 'UTC'), 100) AS [LocalDateTime]
If your EST date was '2018-03-22 22:48:24.893' the output UTC date would be 'Mar 22 2018 2:48AM'.
Upvotes: 1
Reputation: 2014
I would say declare it as variable and get datetime info from the datetimeoffset
Convert to datetime
will do the trick
DECLARE @MyUtctime DATETIMEOFFSET
SET @MyUtctime = (
SELECT getdate() AT TIME ZONE 'EASTERN standard time' at TIME zone 'UTC'
)
SELECT CONVERT(DATETIME, @MyUtctime, 1)
SELECT getdate()
Upvotes: 1