Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String date in to Date type

 
Jayanath
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Im taking the date as dd/MM/yyyy from the user.I want to save it in the database which holds dates in Dste type.
Part of the codings Ive used are given below.


String TodaysDate = "12/30/2003";
SimpleDateFormat formatter= new SimpleDateFormat ("dd/MM/yyyy");

Date today = formatter.parse(TodaysDate);

and so on..

But this doesnt work.
Anyone knows how to convert string date to Date type to save in to a db as well as give the date to the user when required in string format.

Pls help me.
Thanks in advanced for any help...


[ May 25, 2004: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a JSP question, so I'm moving this along to the Java in General(intermediate) forum.
 
Greg T Robertson
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say doesn't work what do you mean if you can provide that you might get more of a response?

You do know that the format you are giving is for month day year, but yet your string appears to be day month year. Date formatter is the way to do this in general though.
 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jayanath,

Please check this java script whihc you cann add in your any .js file and use it properly, since i have this so I am pasting it here, this method will take date string in mm/dd/yyyy format and return you the Date object.

which you can store in ddatabase, please tell me if you need anything else.

 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String TodaysDate = "12/30/2003";
SimpleDateFormat formatter= new SimpleDateFormat ("dd/MM/yyyy");


Your date is in the mm/dd/yy format and you are trying to parse it using dd/mm/yy format. 12 is month,30 is day and 2003 is year. so Use following code to parse this date.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic