Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to DATE

 
marys joseph
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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,
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • 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
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • 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...
 
Greg T Robertson
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic