• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

String date in to Date type

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67504
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a JSP question, so I'm moving this along to the Java in General(intermediate) forum.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic