If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Format Date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Mar 2004
Posts: 50
Thanks RBARAER for that insightful answer.

Ishan
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Aug 2004
Location: France
Posts: 754
You're welcome. I'm glad it helped you.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On