DateTimeOffset.Now in T-SQL

34,980

Maybe.

This would give you the local time of the server where SQL is installed.

Do you want to store timezone etc too? If so, SYSDATETIMEOFFSET() may be better

Share:
34,980
Robert
Author by

Robert

Updated on January 12, 2020

Comments

  • Robert
    Robert over 4 years

    I'm executing a INSERT to a sql 2008 db. How do I specify in T-SQL to insert NOW in a DATETIMEOFFSET column? GETDATE()?

  • keuleJ
    keuleJ over 5 years
    Actually you get an offset (e.g. +02:00), not a time zone (e.g. 'W. Europe Standard Time').
  • ZygD
    ZygD over 5 years
    Then you need something like DECLARE @TimeZone VARCHAR(50) EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SYSTEM\CurrentControlSet\Control\TimeZoneInformation', 'TimeZoneKeyName',@TimeZone OUT SELECT @TimeZone. The problem is ambiguity: multiple timezones can have the same time offset from UTC