I have the following code to check if a given date is valid
SimpleDateFormat fromformatter = new SimpleDateFormat("MMYY");
fromformatter.setLenient(false);
try {
fromformatter.parse(dateString);
valuesQuery.append("'" + dateString+ "',");
} catch (ParseException pe) {
pe.printStackTrace();
valuesQuery.append("'notDate" + dateString+ "',");
}
Now, when I get dateString = "1803";
which is not a valid date, no exception is thrown. The date format that is being used here is MMYY
.
What am i doing wrong?
Note that a regex will not help me as the date format will change.