Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does DATETIME type include timezone information?

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?

like image 536
Mr. Boy Avatar asked Apr 23 '26 05:04

Mr. Boy


2 Answers

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.

like image 151
Mr. Boy Avatar answered Apr 28 '26 05:04

Mr. Boy


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.

like image 28
Ryan M Avatar answered Apr 28 '26 05:04

Ryan M