0

I have a table that looks like this:

utc date                       est date
2018-03-01 07:06:38.000
2018-03-01 07:07:38.000

est date is blank. I have a select statement that calculates EST time.

How do i update the est date column from my select statement?

SELECT toCONVERT(datetime, 
               SWITCHOFFSET(CONVERT(datetimeoffset, 
                                    table."utc date"), 
                            DATENAME(TzOffset, SYSDATETIMEOFFSET())))
       as "etc date"
FROM table where  "utc date" > '2017-10-01' 
1
  • This should be a basic update statement from select like so.
    – Zane
    Dec 12, 2018 at 19:03

1 Answer 1

3

UPDATE syntax:

UPDATE [table]
SET [est date] = toCONVERT(datetime, 
                           SWITCHOFFSET(CONVERT(datetimeoffset, table.[utc date]), 
                           DATENAME(TzOffset, SYSDATETIMEOFFSET())))
WHERE [utc date] > '2017-10-01' 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.