Date Vaildation

Hello,

I have a Date property with edit validate configured to it to restrict user to select Current date or Future Date only. Earlier It was working fine from yesterday it is not accepting current date and throwing an error when we choose current date. I kindly request to solve my issue and below is the code I’m using in edit validate rule.

Thank you!!

if (theValue.trim().length() == 0) {
return false;
}
java.util.Date theDate = tools.getDateTimeUtils().parseDateTimeString(theValue);
java.util.Date presentDate= new java.util.Date();
theProperty.addMessage("Invalid date ");
return (theDate != null && (theDate.getDate()==presentDate.getDate() || theDate.after(new java.util.Date())));

@AkhilR03

Try with this alone (date is not in past)

!theDate.before(new java.util.Date());

@AvikMitra

Thanks for the reply but still it is throwing same error

@AkhilR03

Share the updated code.

@AvikMitra

Updated code

if (theValue.trim().length() == 0) {
return false;
}
java.util.Date theDate = tools.getDateTimeUtils().parseDateTimeString(theValue);
java.util.Date presentDate= new java.util.Date();
theProperty.addMessage("Invalid date ");
return (theDate != null && (theDate.getDate()==presentDate.getDate() || !theDate.before(new java.util.Date())));

@AkhilR03

you don’t need to add the present day condition anymore. Just validate if date is not in past. This means date is either in present or future.

@AvikMitra

Updated Code

if (theValue.trim().length() == 0) {
return false;
}
java.util.Date theDate = tools.getDateTimeUtils().parseDateTimeString(theValue);
java.util.Date presentDate= new java.util.Date();
theProperty.addMessage("Invalid date ");
return (!theDate.before(new java.util.Date()));

If this is the code you are suggesting, this is also not working. I kindly request you to share me the right code.

@AkhilR03

Attached.

Date Validation.txt (706 Bytes)

@AvikMitra

Thank You very much Arvikmitra, there was some time zone miss match.