Validate date smaller than current date [closed]

1

My question is as follows. I have a JSP form for registering students with multiple attributes, one of them is the date of birth. Until then I was registering the date only by validating the format (dd / MM / yyyy) and with annotations. But now, I really need to validate the date in a way that the user can not register a date later than today's date and none of the ideas I've had and implemented in JPA have worked. Does anyone know a way to do this?

    
asked by anonymous 17.11.2016 / 14:56

1 answer

0

Do this:

public static boolean comparaDatas(String psDate1, String psDate2) throws ParseException{
        SimpleDateFormat dateFormat = new SimpleDateFormat ("dd/MM/yyyy");
        Date date1 = dateFormat.parse(psDate1);
        Date date2 = dateFormat.parse(psDate2);
        if(date2.after(date1)) {
            return true;
        } else {
            return false;
        }
    }
    
17.11.2016 / 16:28