• 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:

String to DATE

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am reading data from excel file and updating the sql table. When I read all the contents from excel file are in String format. How do I change the string into Date.

For ex:

String s ='3/31/2003'

When I tried Date renew = new Date(s); it is not storing the correct date.

I need to insert 3/31/2003 into the DB table.

any suggestions?

thanks,
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the api docs for java.text.SimpleDateFormat. It provides the mechanism for converting strings into date objects and vice-versa
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The simplest way is...

Cut your String s into month, day and year and use the GregorianCalendar(int year, int month, int dayOfMonth) Constructor to create a GregorianCalendar object... Later get a date instance from it and then do things with DB...

Hope it helps...
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GregorianCalendar is nice EXCEPT that you have to be very careful with getting Dates & Timestamps you can lose some hours (this can affect Dates too). I second the DateFormat classes.
 
reply
    Bookmark Topic Watch Topic
  • New Topic