-3

How can I cast this string date to datetime in oracle.

Sun Apr 21 21:32:13 IRDT 2013

"IRDT" is the time zone and its equal in all records.

Ammar Bozorgvar
  • 1,230
  • 19
  • 30
  • What is `IRDT`? Is that a time zone? – Patashu May 21 '13 at 06:28
  • so you want from that string to get a date or a timestamp? – Teshte May 21 '13 at 06:29
  • 1
    There are tons of examples available on Stackoverflow. Have you tried any of them? For example, ["What is the Oracle date formatting mask for time zones?"](http://stackoverflow.com/questions/2291082/what-is-the-oracle-date-formatting-mask-for-time-zones) – YasirA May 21 '13 at 06:33

2 Answers2

2

If you don't care about timezone and it is equal in all records you can try

SELECT TO_DATE('Sun Apr 21 21:32:13 IRDT 2013'
              ,'DY MON DD HH24:MI:SS "IRDT" YYYY') "date"
FROM dual;

Output:

|                         DATE |
--------------------------------
| April, 21 2013 21:32:13+0000 |

SQLFiddle

But if you need to take into account and store timezone info then you might want to use TIMESTAMP WITH TIME ZONE data type and TO_TIMESTAMP_TZ()

peterm
  • 91,357
  • 15
  • 148
  • 157
0

Use this : http://www.techonthenet.com/oracle/functions/to_date.php

Basically you would use to_Date('Sun Apr 21 21:32:13 IRDT 2013','mask'), and you create the mask string using the table from that link

Teshte
  • 624
  • 1
  • 7
  • 26