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()?
On Transact SQL language the datetimeoffset is part of date and time data types and define a date that is combined with a time of a day that has time zone awareness. Datetimeoffset syntax: Property.
SYSDATETIMEOFFSET() Examples in SQL Server (T-SQL) In SQL Server, the transact-sql SYSDATETIMEOFFSET() function returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. This value includes the time zone offset.
The idea of storing dates and times with a time zone offset is relatively new to SQL Server and is often underutilized in applications. One can hope that it becomes more commonplace as more SQL developers learn about it and the ease in which it can be implemented.
The datetimeoffset data type includes the date and time with a time zone offset. It also has a fractional seconds part between 0 and 7 (this depends on how many fractional seconds are assigned to it). This is done by using the datetimeoffset (n) syntax. If you don’t specify this, it will use 7 (the default).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With