DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Varchar2(4) - Date

  1. #1
    Join Date
    Jul 2001
    Posts
    334

    Varchar2(4) - Date

    I have a column accounting_date varchar2(4) and populated with the value 0412,0402 etc. I need to convert it as a date like first two digits are year and last two digits are Month. the format I am looking is
    Dec, 2004
    Feb, 2004

    I have used to_date(substr(accounting_date,-2)||substr(accounting_date,1,2),'MM-YY') query returns
    1-Feb-2004
    1-Dec-2004

    Why I am getting DD?

    Thanks.

  2. #2
    Join Date
    Jul 2001
    Posts
    334
    Hi I think I have resolved this issue by using the below
    substr(to_char(to_date(substr(accounting_date,-2)||substr(accounting_date,1,2),'MM/YY')),4,8).

    Please correct if this is ok.

    Thanks.

  3. #3
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    select to_date(a, 'YYMM') from x;

  4. #4
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    you dont want day then you have to modify your nls_date_format parameter or change back to char again

    select to_char(to_date(a, 'RRMM'), 'MON-RR') from x

  5. #5
    Join Date
    Jul 2001
    Posts
    334
    Hi Pando,
    Thanks you for resolving the issue. Appreciate!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width