• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

DB2 Date format to Oracle Date format?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to convert a DB2 date (or timestamp) to Oracle format (MM/dd/yyyy).
Please suggest the easiest method.
Thnx,
Sam.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
What is the format for the DB2 date? Have you tried using java.text.SimpleDateFormat?
Regards
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought the default Oracle format was DD-MON-YYYY, as in '06-JAN-2004'. I think that's the way dates come out in DB2 also. Actually, I think that is some kind of standard.
Anyway, if you have a string in a particular format, you can convert in Oracle using the TO_DATE and TO_CHAR functions.
For example, if you have a string that looks like '06-JAN-2004', and you want to display a string that looks like '01/06/04', you could
1) Convert the string to a Date with TO_DATE( string, 'DD-MON-YYYY')
2) Convert the Date back to a string with TO_CHAR( date, 'MM/DD/YY')
Putting it all together, it looks like this:
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with John, use the method format, in class java.text.SimpleDateFormat to format de java.sql.Date object that you extract from ResultSet.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic