Fred Fickleberry III Fred Fickleberry III - 1 year ago 63
SQL Question

How do I update a column's offset in SQL Server?

I converted a table's

DateTime
field to
DateTimeOffset
, but now the offset is automatically set to +00:00.

I need to change all DateTimeOffset fields of this table to an offset of +1:00.

How can I do this in an update query?

Answer Source

You can use SWITCHOFFSET to change the offset. You will need to subtract the amount of hours though from the date if you don't want the date to change.

SELECT  SWITCHOFFSET(DATEADD(hh, -1, CAST (GETDATE() AS DATETIMEOFFSET)),
                         '+01:00')