I want to use UTC timestamps exclusively in an MSSQL database. When writing the current timestamp I can use system methods like GETDATEUTC and we have agreed with suppliers that timestamps sent from external sources will also be provided as implicit UTC - but when writing these to the DB do I need to tell MSSQL that it is a UTC date somehow? Or is it my responsibility to know what timezone I'm using?
To provide an answer, in short Neither Datetime nor Datetime2 encodes timezone information, only the raw date/time data specified. It is up to the developers/DBAs/users to agree what the data means.
No, a DATETIME is independent of any time zone.
It is simply an abstract representation of instant in time; that instant represents different times/dates in different time zones, but it is the same instant in time in all of them, and thus the same DATETIME.
You can convert it to a specific time zone using AT TIME ZONE. That will give you a datetimeoffset representing the time and date in a particular time zone that corresponds to that instant in time.
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