简体   繁体   English

将日期值转换为PST以进行比较:Oracle

[英]Convert date value to PST for comparison:Oracle

I have 2 questions: 我有两个问题:

  1. I want to compare a field whose data type is "Date" against a given date. 我想将给定日期的数据类型为“日期”的字段进行比较。 The DB is oracle and being a mysql guy I'm finding it difficult to come up with simple queries. 数据库是oracle,作为mysql的人,我发现很难提出简单的查询。 The field("date_closed") stores date in UTC format (24-Aug-2011 18:55:11 for example) and I want to convert it to PST for comparison. field("date_closed")以UTC格式存储日期(24-Aug-2011 18:55:11 for example) ,我想将其转换为PST以进行比较。 I tried this query but it returns some extra rows in the data set(obviously): 我尝试了此查询,但是它返回了数据集中的一些额外的行(显然):

    select * from table1 where trunc(date_closed)=to_date('2011-08-24','yyyy-mm-dd')

    How do I covert to PST format before comparison? 比较之前,我该如何转换为PST格式?

  2. In the same query how do I compare "date_closed" against the current date? 在同一查询中,如何将“ date_closed”与当前日期进行比较?

You need the NEW_TIME function 您需要NEW_TIME函数

Dates don't include timezone in Oracle, and are assumed to be in the database timezone (which may by UTC but probably isn't). 日期在Oracle中不包括时区,并且假定为在数据库时区中(可能是UTC,但可能不是)。 You should look at the TIMESTAMP WITH TIMEZONE data types. 您应该查看TIMESTAMP WITH TIMEZONE数据类型。

Also, bear in mind that if you are comparing to the current date - I assume that you want to strip off the timestamp and compare only the day. 另外,请记住,如果要与当前日期进行比较-我假设您要剥离时间戳并仅比较日期。

So, if new_time(date_closed,'GMT','PST') translates the date , your where clause will be comparing something like 因此,如果new_time(date_closed,'GMT','PST')转换date,则您的where子句将比较类似

trunc(new_Time(date_closed,'GMT','PST')) = trunc(sysdate) trunc(new_Time(date_closed,'GMT','PST'))= trunc(sysdate)

to get all records with date_closed on the current day in PST. 以获取当天PST中date_closed关闭的所有记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM