I have a DATE datatype mysql column in a table. I want to set the value of that column from my java code in the format YYYY-MM-DD
I used following code to test these formats..
Calendar c = Calendar.getInstance();
c.setTime(new Date());
String d = c.YEAR+ "-"+c.MONTH+"-"+c.DATE;
But I get some wierd output if i print out that value in console. Please help. How else can I accomplish this ?
What you have to do is:
If I remember correctly you also have to add +1 to the month as it returns offset (counted from 0) instead of just month value (which is stupid for me, but I didn’t do the design).
Also, you might like to check SimpleDateFormat and its capabilities to format a date in nice way.