I'm trying to format a date formatted result from a database into date only. ("dd"). The query results are formatted like this, 2014-05-17 00:00:00
I want to extract only "17", How can I achieved this? This is my code.
String query = "SELECT DISTINCT date FROM Attendance;";
Object[][] queryResult = connectToDB(headerQuery);
for(int x = 0; x < queryResult.length; x++){
for(int y=0; y < queryResult[x].length; y++){
Object temp = queryResult[x][y];
SimpleDateFormat format = new SimpleDateFormat("dd");
System.out.print(format.format(temp));
System.out.println(temp+ "<-----");
}
System.out.println("---");
}
this is my error
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
UPDATE: I've changed the for-loop into this:
for(int x = 0; x < queryResult.length; x++){
for(int y=0; y < queryResult[x].length; y++){
String temp = (queryResult[x][y]).toString();
SimpleDateFormat format = new SimpleDateFormat("dd");
Date date = (Date) format.parse(temp);
System.out.println(date+ "<-----");
}
System.out.println("---");
}
but it still does not format the date;