*
The moose likes Beginning Java and the fly likes Date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date format" Watch "Date format" New topic
Author

Date format

santosh garg
Greenhorn

Joined: Feb 02, 2009
Posts: 10
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
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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..


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Has nothing to do with JavaScript/HTML. Moving to JIG B

Eric
 
Consider Paul's rocket mass heater.
 
subject: Date format
 
Similar Threads
Any Alternative for this CODE !!!!!!
Convert from String to java.sql.Date
Calculate Yesterday's date
java.util.Date problem
java.sql.Date