Search code examples
sqlsql-serverdatetimedefault-constraint

how to set default constraint to UTC time with TimeZone in SQL Server


I have to add default value to a datetime column with UTC time with Timezone, right now I am using the GETUTCDATE() in default constraint, but it is not adding the timezone information to the column.

Please help me.


Solution

  • The type that includes timezone information (specifically, the offset) is datetimeoffset. GETUTCDATE returns a plain old DATETIME which has no timezone indication, not even a Local vs UTC indicator.

    If you care about timezones and offsets, use a datetimeoffset column and ` SYSDATETIMEOFFSET as its default