0

I would like to convert the following date to this format(DD-MON-YYYY).

I tried executing the below query but I got the error saying "date format not recognised".

select to_char(to_date('Sat Dec 01 00:00:00 IST 2012','EEE Mon dd HH:mm:ss z yyyy'),'DD-MON-YYYY') from dual;
3
  • what date? you seem to be missing something information. Also what database Commented May 14, 2013 at 2:43
  • 1
    Selecting from dual to me would indicate its Oracle Commented May 14, 2013 at 2:52
  • I am using Oracle10g. Date is Sat Dec 01 00:00:00 IST 2012 Commented May 14, 2013 at 2:56

1 Answer 1

1

For everything but the time zone:

'DY MON DD HH24:MI:SS YYYY'

For timezone support you need to use a conversion function that supports a timezone like TO_TIMESTAMP_TZ() and have the time zone name as one Oracle recognizes in the form it recognizes.

select to_char( TO_TIMESTAMP_TZ( 
        REPLACE( 'Sat Dec 01 21:00:00 IST 2012','IST','Asia/Calcutta'),
       'DY MON DD HH24:MI:SS TZR YYYY'),'DD-MON-YYYY') from dual;

The relation between time zone names and abbreviations is one to many for most.

SELECT tzname, tzabbrev FROM v$timezone_names where TZABBREV = 'IST'

For your example it would probably be easier to remove some or all of the date parts you don't need in the output before conversion.

select to_char( to_date( replace('Sat Dec 01 21:00:00 IST 2012','IST',''),
       'DY MON DD HH24:MI:SS YYYY'),'DD-MON-YYYY') from dual;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.