Results 1 to 4 of 4
Thread: Date Format for Oracle..
- 11-01-2010, 01:10 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 18
- Rep Power
- 0
Date Format for Oracle..
Hi All
I am trying to update/insert a date in the Oracle DB by using the below method for the exact desired date format as per my requirement. But it is providing the date in "2010-11-01 18:29:43.717", but i need in this pattern : "2010-11-01 18:29:43 PM". means either (AM/PM) should be visible according to the time.
Can u guide me...
OUTPUT: Date after convert to timestamp : 2010-11-01 18:29:43.717Java Code:public void dateFormat() { DateFormat formatter; formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss s"); java.util.Date date = new java.util.Date(); System.out.println("Date inbetween convert : " + date); long dateLong = (date).getTime(); Timestamp tstamp = new Timestamp(dateLong); System.out.println("Date after convert to timestamp : " + tstamp); //stmt.setTimestamp(5, tstamp); This is used while inserting in to DB }
Thanks in Advance..
- 11-01-2010, 09:04 PM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Java Code:java.util.Date date = new java.util.Date(); DateFormat formatter= new SimpleDateFormat("dd-MM-yyyy hh:mm:ss a"); System.out.println(formatter.format(date));
- 11-02-2010, 05:06 AM #3
Member
- Join Date
- Jul 2010
- Posts
- 18
- Rep Power
- 0
Dear FON
Thank you very much for your quick response, i tried like this as well but the thing which we are getting is String, then i am unable to insert this String form of Date into the DB means:
I am using PreparedStatement for inserting a record.. can u guide for this.Java Code:stmt.setTimestamp(5, tstamp); // stmt.setDate(5, longtype); stmt.setObject(5, stringtype); //By using this throwing error use to_date fun().
- 11-02-2010, 10:06 AM #4
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Why does it matter what format is in DB?
You can just use java.sql.Timestamp on java side and sysdate
on oracle side to insert current date simply.
After that, use oracle functions to_char with to_date and transform inserted value in format you need.
Those this make sense?Java Code:SELECT TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS PM') FROM dual;
Similar Threads
-
Format date
By mine0926 in forum New To JavaReplies: 11Last Post: 08-04-2010, 01:56 AM -
julian date to full date format
By judy318 in forum New To JavaReplies: 7Last Post: 11-02-2009, 12:17 PM -
Date Format
By learnspring in forum New To JavaReplies: 1Last Post: 11-16-2008, 05:16 PM -
how to convert date format
By saran123 in forum New To JavaReplies: 5Last Post: 10-16-2008, 06:10 PM -
problems with Date format
By tommy in forum New To JavaReplies: 1Last Post: 07-25-2007, 08:38 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks