Results 1 to 6 of 6
  1. #1
    karq is offline Member
    Join Date
    May 2010
    Posts
    63
    Rep Power
    0

    Default Convert date from database

    How do i convert the date what I fetch from the database to 06.10.2010

    yyyy-MM-dd to dd.MM.yyyy

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    SimpleDateFormat
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default

    The date you fetch from a database has no format, so you are not changing from one String format to another. Unless, of course, it's not actually a DATE column...

    Just thought I'd throw that in there...:)

  4. #4
    karq is offline Member
    Join Date
    May 2010
    Posts
    63
    Rep Power
    0

    Default

    Thanks, got it, simpledateformat did the trick.

    Here's the code:

    Java Code:
    //create SimpleDateFormat object with source string date format
                        SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        Date date = sdfSource.parse(rs.getString(3));
    
                        //New date format
                        DateFormat dateformat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    
    
                        //Convert
                        String newDate = dateformat.format(date);

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default

    No no no.
    Why are you converting the perfectly useable Date object back to a String?
    I do hope you are not inserting that String into the db and letting the db auto-convert to a DATE...that's a Bad Thing.

  6. #6
    ajaysingh87 is offline Member
    Join Date
    Jul 2010
    Location
    India, Mumbai
    Posts
    5
    Rep Power
    0

Similar Threads

  1. inserting date in oracle database
    By jackjosh_in in forum Advanced Java
    Replies: 6
    Last Post: 05-23-2010, 06:38 PM
  2. o get the missing date from database
    By javastuden in forum New To Java
    Replies: 0
    Last Post: 12-11-2009, 11:15 AM
  3. Replies: 2
    Last Post: 02-11-2009, 04:43 AM
  4. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  5. how to convert date format
    By saran123 in forum New To Java
    Replies: 5
    Last Post: 10-16-2008, 06:10 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
  •