[英]Is there a SQL function to convert to PST or PDT depending on the date?
I would like to convert times from pacific to UTC.我想将时间从太平洋转换为 UTC。 However, I must first convert the times to either PST or PDT depending on the date.
但是,我必须首先根据日期将时间转换为 PST 或 PDT。 Is there a SQL function that can do this, or does anyone have any advice for creating this function?
是否有 SQL function 可以做到这一点,或者有人对创建此 function 有任何建议吗?
The link you provided is pretty much useless as a guide to timestamps.您提供的链接作为时间戳指南几乎没有用。 If you are going to work with timezones then store your timestamps in a
timestamp with time zone
field.如果您要使用时区,则将时间戳存储在
timestamp with time zone
字段中。 The timezone
will not actually be stored but the timestamp will be stored as a UTC
. timezone
实际上不会被存储,但时间戳将被存储为UTC
。 Whenever a timestamp
is entered it is rotated to a UTC
value.每当输入
timestamp
,它都会旋转为UTC
值。 This makes working with value easier down the road.这使得在未来更容易处理价值。 If you want to take into account
DST
transitions you will need to use full timezone names eg US/Pacific
, as they cover the two offsets( PST/PDT
) that constitute the standard/daylight savings timezones.如果您想考虑
DST
转换,您将需要使用完整的时区名称,例如US/Pacific
,因为它们涵盖了构成标准/夏令时时区的两个偏移量( PST/PDT
)。 As you found using the offset PST(-08)
or PDT(-07)
gets you a fixed offset regardless of date.正如您发现的那样,使用偏移
PST(-08)
或PDT(-07)
可以获得固定的偏移量,而不管日期如何。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.