Results 1 to 4 of 4
  1. #1
    sasi.tati is offline Member
    Join Date
    Jul 2010
    Posts
    18
    Rep Power
    0

    Question 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...

    Java 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
        }
    OUTPUT: Date after convert to timestamp : 2010-11-01 18:29:43.717

    Thanks in Advance..

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    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));

  3. #3
    sasi.tati is offline Member
    Join Date
    Jul 2010
    Posts
    18
    Rep Power
    0

    Default

    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:

    Java Code:
    stmt.setTimestamp(5, tstamp); //
    stmt.setDate(5, longtype); 
    stmt.setObject(5, stringtype); //By using this throwing error use to_date fun().
    I am using PreparedStatement for inserting a record.. can u guide for this.

  4. #4
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    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.

    Java Code:
    SELECT TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS PM') FROM dual;
    Those this make sense?

Similar Threads

  1. Format date
    By mine0926 in forum New To Java
    Replies: 11
    Last Post: 08-04-2010, 02:56 AM
  2. julian date to full date format
    By judy318 in forum New To Java
    Replies: 7
    Last Post: 11-02-2009, 01:17 PM
  3. Date Format
    By learnspring in forum New To Java
    Replies: 1
    Last Post: 11-16-2008, 06:16 PM
  4. how to convert date format
    By saran123 in forum New To Java
    Replies: 5
    Last Post: 10-16-2008, 07:10 PM
  5. problems with Date format
    By tommy in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:38 PM

Posting Permissions

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