与 datetime2 相比,在 datetimeoffset 字段中存储 UTC 时间戳有什么好处吗?看来它们本质上是一样的。
+------------------------------------+-----------------------------+
| datetimeoffset | datetime2 |
|------------------------------------+-----------------------------|
| 2021-02-12 16:48:11.0677934 +00:00 | 2021-02-12 16:48:11.0677934 |
+------------------------------------+-----------------------------+
datetimeoffset
数据类型将允许比较同一时间的不同偏移量。例如:
SELECT 'equal'
WHERE
CAST('2021-02-12T15:48:11.0677934-01:00' AS datetimeoffset) = CAST('2021-02-12T16:48:11.0677934+00:00' AS datetimeoffset).
datetime2
节省存储空间。 datetimeoffset
需要 10 个字节的存储空间,而 datetime2
对于精度 5 或更高的精度需要 8 个字节,对于精度 3-4 需要 7 个字节,对于精度 2 或更低需要 6 个字节。