我使用此 T-SQL 语句从表中获取日期和时间作为秒数,日期和时间位于我当前的时区,返回的秒数位于我当前的时区,我如何返回秒数改为 UTC 时区?
SELECT
TableName,
CAST(DATEDIFF(second, '1970-01-01', LastUpdateDate) AS BIGINT) TimestampInSeconds
FROM
SynchronizationVersions r
WHERE
LastUpdateDate IS NOT NULL
将您的
datetime
值转换为具有正确时区的 datetimeoffset
,然后与 UTC 的 1970-01-01 进行比较:
SELECT DATEDIFF_BIG(SECOND, '1970-01-01T00:00:00+00:00', LastUpdateDate AT TIME ZONE 'Alaskan Standard Time')
FROM dbo.YourTable;