使用我们/中央时区检索当前时间戳的sql server查询是什么?
答案 0 :(得分:0)
您需要本地和远程时区,因此Oracle可以计算差异,例如
SELECT FROM_TZ(CAST(sysdate AS TIMESTAMP), 'America/New_York')
AT TIME ZONE 'America/Los_Angeles'
FROM DUAL;
30.10.14 08:45:08,000000000 AMERICA/LOS_ANGELES
和
SELECT FROM_TZ(CAST(sysdate AS TIMESTAMP), 'America/New_York')
AT TIME ZONE 'America/Chicago'
FROM DUAL;
30.10.14 10:46:17,000000000 AMERICA/CHICAGO
您可以使用以下命令获取时区名称列表:
SELECT tzname, tzabbrev FROM V$TIMEZONE_NAMES;
所以你可以这样做:
SELECT FROM_TZ(CAST(sysdate AS TIMESTAMP), 'America/New_York')
AT TIME ZONE 'US/Central'
FROM DUAL;
假设你在纽约。
答案 1 :(得分:0)
如果这是针对SQL Server 2008或更高版本,则会提供特定时区偏移量的时间。我不知道你是否可以提供时区名称,并且使用这种方法,你必须自己处理夏令时。
declare @dt datetimeoffset = switchoffset(convert(datetimeoffset, getutcdate()), '-06:00')
select getutcdate() as utc, @dt as [datetimeoffset], cast(@dt as datetime) as [datetime]
答案 2 :(得分:0)
Time zone support was added with SQL Server 2016. You can now do this:
SELECT SYSDATETIMEOFFSET() AT TIME ZONE 'Central Standard Time'
Note that the identifier Central Standard Time
is the Windows time zone ID for Central Time in US and Canada. It is inclusive of both CST and CDT.