是否有将时区转换为本地时间(ldt)的sql函数?

njthzxwz  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(431)

我对sql非常陌生,尝试使用以下命令从数据库(flight)中提取数据表:

select 

flight.FLT_NBR,
flight.LEG_NBR,
flight.LEG_TAIL_NBR,
flight.LEG_IATA_ORIG_CD as FLT_SCHD_ORIG_ARPT_CD,
flight.LEG_IATA_DEST_CD as FLT_SCHD_DEST_ARPT_CD,
flight.SCHD_ARR_TMSTP as Scheduled_Arrival,
flight.ACTL_ARR_TMSTP AS Actual_Arrival,
flight.SCHD_DPRT_TMSTP as Scheduled_Departure,
flight.ACTL_DPRT_TMSTP AS Actual_Departure,

from home/tulips/FT_FLIGHT_LEG flight

现在的问题是有多个国家的来源地和目的地不同的时间。如何将所有国家的时区合并到一起?我尝试使用命令作为时区'utc'如下面,但它没有工作。。。可能是我加错地方了?

select 

flight.FLT_NBR,
flight.LEG_NBR,
flight.LEG_TAIL_NBR,
flight.LEG_IATA_ORIG_CD as FLT_SCHD_ORIG_ARPT_CD,
flight.LEG_IATA_DEST_CD as FLT_SCHD_DEST_ARPT_CD,
flight.SCHD_ARR_TMSTP as Scheduled_Arrival as time zone 'UTC',
flight.ACTL_ARR_TMSTP AS Actual_Arrival as time zone 'UTC',
flight.SCHD_DPRT_TMSTP as Scheduled_Departure as time zone 'UTC',
flight.ACTL_DPRT_TMSTP AS Actual_Departure as time zone 'UTC',

from home/tulips/FT_FLIGHT_LEG flight

请帮我找到一种方法,让所有的预定到达、实际到达、预定离开和实际离开都有一个时区

2o7dmzc5

2o7dmzc51#

你想要的表达方式是 at time zone ,不是 as time zone .
为了使用它,你需要知道原来的时区 datetime 值表示。例如,我在澳大利亚悉尼有一台sql server getdate() 将返回我的本地日期和时间。但是,要将其转换为utc,我必须首先通知sql该值以aus eastern standard time开始,然后要求它通过链接将其转换为utc at time zone 一起表达。这样地:

select getdate() at time zone 'AUS Eastern Standard Time' at time zone 'UTC'

如果您不知道原始datetime值的时区,sql就无法知道如何将其更改为其他时区的值。

相关问题