If I have dates that are in this format: Sep-29-07 13:45:00 PDT
How would I convert this into a Date object in oracle 11g? I have tried this:
SELECT TO_DATE(PublishDate, 'MON-DD-YY HH24:MI:SS')
FROM Order;
But I am getting an error saying:
ORA-01830: date format picture ends before converting entire input string
If you have only one time zone's dates, you can just ignore the timezone part using:
select to_date(PublishDate, 'MON-DD-YY HH24:MI:SS "PDT"')
from Orders;
If you plan to support multiple timezones, then store them with timestamp with time zone
format. use correct timezone abbreviation (PST instead of PDT - See this ) and convert the string, use to_timestamp_tz
.
select to_timestamp_tz(PublishDate, 'MON-DD-YY HH24:MI:SS TZR')
from Orders;
or perhaps, convert them in one local time zone. See this answer for that
You can ignore the timezone by using:
SELECT TO_DATE(SUBSTR(PublishDate, 1, length(PublishDate) - 4), 'MON-DD-YY HH24:MI:SS')
However, if you want to handle different timezones, you need to store the standard format, something like 'America/Los_Angeles'
.
For example:
SELECT TO_TIMESTAMP_TZ(PublishDate, 'MON-DD-YY HH24:MI:SS TZR')
from (select 'Sep-29-07 13:45:00 America/Los_Angeles' as PublishDate from dual) x;
You can this modify this with 'PDT'
, but that is not acceptable by itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.