• 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

Date format

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have date in textbox which I am getting in MM-DD-YYYY format but I have to insert into mysql database which accepts it in yyyy-mm-dd format. is there any way to convert it.

I have tried with the following code

java.text.DateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
java.util.Date mySDate = format.parse(sdate);
java.util.Date myEDate = format.parse(edate);

but it gives me java.text.SimpleDateFormat(unknown) error.
please anyone provide me solution for this.

Thanks in advance
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santosh garg wrote:I have date in textbox which I am getting in MM-DD-YYYY format but I have to insert into mysql database which accepts it in yyyy-mm-dd format. is there any way to convert it.

I have tried with the following code

java.text.DateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
java.util.Date mySDate = format.parse(sdate);
java.util.Date myEDate = format.parse(edate);

but it gives me java.text.SimpleDateFormat(unknown) error.
please anyone provide me solution for this.



I don't know whats this error about, but what I thought for this is, You need to make first instance of SimpleDateFormat class which takes "MM-dd-yyyy" format , then parse the date you are receiving as a string, this makes a "Date" object of your format. Once you get the Date from string convert it into "yyyy-MM-dd", using another instance of SimpleDatFormat class..

Try this..
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has nothing to do with JavaScript/HTML. Moving to JIG B

Eric
 
Yup, yup, yup. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic