Click here to Skip to main content
15,895,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How i can convert string to data so i can save my date to sql server?

i am using netbeans JdateChooser which give me date in "
Sun Jan 01 00:00:00 PKT 2017
" ...
but i want in "YYYY-MM-DD" .

What I have tried:

DateFormat df=new SimpleDateFormat("YYYY-MM-dd");
       Date date= dateChooser.getDate();
       Date StringToDate=df.parse(dateString);
       System.out.println("String to Date = "+StringToDate);
Posted
Updated 25-Feb-17 16:33pm
Comments
[no name] 25-Feb-17 17:39pm    
You don't. Save the date as a date not as a string. You are begging for trouble if you do.

1 solution

Never do that. Not only date, data should be treated in its natural form meant for storage on data layer. No matter how you format them, they will just be stored as binary, what is the point? Simply save the date user selected from
JdateChooser
to a date type field in the database. Upon retrieval, then format it to the desired format you want for presentation (layer) purpose.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900