• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • 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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic