| Author |
java.sql.Date, Oracle - DateFormating?
|
Vikrama Sanjeeva
Ranch Hand
Joined: Sep 02, 2001
Posts: 756
|
|
Hi, I have a column [USERDATE] of type DATE in Oracle. Which accepts dates in form of: 28-JUN-04. I am using query SELECT sysdate FROM dual to extract date from DB. This query returns date in 2004-06-28 format. Now I want to convert 2004-06-28 into 28-JUN-04 format. Kindly tell me how can I do this? Remember, column [USERDATE] does not accept date even in this format 28-06-04. Here is the code fragment which extracts date from DataBase. Bye, Viki. [ June 28, 2004: Message edited by: Vikrama Sanjeeva ]
|
Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
java.text.SimpleDateFormat
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Karthikeya Shashikanth
Greenhorn
Joined: Jun 28, 2004
Posts: 1
|
|
Try select to_char(sysdate, 'DD-MMM-YY') FROM DUAL I dont have ORACLE I have gone thru this long back. Hope this helps Regards Karthik
|
 |
Blake Minghelli
Ranch Hand
Joined: Sep 13, 2002
Posts: 331
|
|
That does not return any particular format, just a Date object which is not much more than a number of milliseconds that corresponds to some point in time. If you are trying to get that date and store it into the "userdate" column, then you should not have to worry about the format if you are using a PreparedStatement. For example, you should be able to do something like this: Now, if you are trying to build an sql string and use a generic Statement to execute it, then you do have to format the date into a String first. As Paul suggested, for that you need to use a SimpleDateFormat. But if possible, you should use a PreparedStatement. Aside from better performance, it also prevents you from having to worry about formatting the date, escaping quotes, etc.
|
Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
|
 |
Vikrama Sanjeeva
Ranch Hand
Joined: Sep 02, 2001
Posts: 756
|
|
Originally posted by Karthikeya Shashikanth: select to_char(sysdate, 'DD-MMM-YY') FROM DUAL
Correct one is select to_date(sysdate,'dd-mm-yy') from dual. When I run this on SQL console: it returns 29-JUN-04. This is fine. But when I call using String date=rs.getString(1); it gives 2004-06-29 format. So problem still exist.
Originally posted by Blake Minghelli: If you are trying to get that date and store it into the "userdate" column, then you should not have to worry about the format if you are using a PreparedStatement
Ok! PreparedStatement is working fine. My problem solved!! Thanks Paul, Karthik, Blake and finally JR for providing a tremendous platform for knowledge sharing. Albeit my problem is solved. But here I have found some generic solution to any DBM date formating. But I cannot understand how to make syntax. See 5.1.6 SQL Escape Syntax in Statements and then * d, t and ts. Further comments on this article with code examples will be highly appreciated. Bye, Viki. [ June 29, 2004: Message edited by: Vikrama Sanjeeva ]
|
 |
 |
|
|
subject: java.sql.Date, Oracle - DateFormating?
|
|
|