Results 1 to 5 of 5

Thread: Format Date

  1. #1
    Join Date
    Mar 2004
    Posts
    50

    Format Date

    Hi,
    In a query , I want to change the display format of date to 'mm-dd-yy'. for this I have to use a combination of to_char and to_date. Doesnt oracle provides a function/way to change the display format of date datatype w/o changing the datatype.


    Thanks,
    Ishan

  2. #2
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Hello,

    Excuse me, but I don't see why you would have to use both to_char and to_date. Wouldn't "TO_CHAR(date_field, 'MM-DD-YY')" be sufficient ? If not, could you post your entire query so that I can see your point and try to help you better ?

    Regards,

    RBARAER

  3. #3
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Ok, I've read your question again, and I think I see your problem. As I already explained once in this forum (about 3 weeks ago), here is how dates are managed by Oracle :

    The date format in Oracle is actually a 7 bytes array, each byte interpreted as an integer between 0 and 255, with :

    At index 0 : the century + 100 (120 for 2004)
    At index 1 : the year within the century + 100 (104 for 2004)
    At index 2 : the month
    At index 3 : the day
    At index 4 : the hours + 1 (16 for 15:30:00)
    At index 5 : the minutes + 1 (31 for 15:30:00)
    At index 6 : the seconds + 1 (01 for 15:30:00)

    Now, when you make Oracle display a date, it is always as a string, but whatever you want Oracle to display, the date is managed internally as shown above. Consequently, you can't return a date with "MM-DD-YY" as a date format, but you can return a date string representation with "MM-DD-YY", or return a date format, and then convert it to a string representation to display it. Note that in SQLPlus, you will always manage dates through one of their string representations. In JDBC or OCCI programs, however, you can work with the Oracle internal date format.

  4. #4
    Join Date
    Mar 2004
    Posts
    50
    Thanks RBARAER for that insightful answer.

    Ishan

  5. #5
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    You're welcome. I'm glad it helped you.

Posting Permissions

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