开发者

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. 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. I tried this query but it returns some extra rows in the data set(obviously):

    select * fro开发者_运维技巧m table1 where trunc(date_closed)=to_date('2011-08-24','yyyy-mm-dd')

    How do I covert to PST format before comparison?

  2. In the same query how do I compare "date_closed" against the current date?


You need the NEW_TIME function

Dates don't include timezone in Oracle, and are assumed to be in the database timezone (which may by UTC but probably isn't). You should look at the TIMESTAMP WITH TIMEZONE data types.


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

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

to get all records with date_closed on the current day in PST.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜