Closed
Date Field Validation
Hi I have a requirement.
I have two date fields - Date 1 and Date 2.
I need to ensure Date 2 is always in the past of Date 1. How can I implement this requirement?
Thank you
This content is closed to future replies and is no longer being maintained or updated.
Links may no longer function. If you have a similar request, please write a new post.
Hi I have a requirement.
I have two date fields - Date 1 and Date 2.
I need to ensure Date 2 is always in the past of Date 1. How can I implement this requirement?
Thank you
Hi Samuel,
You can give a try on @CompareDates function. It accepts two DataTime strings as inputs and returns true if the first date argument is after the second.
If you are using a property of type Date, you can use this function by hard coding timestamp like below.
@CompareDates(@ConvertStringToDate(.Date1)+"T000000.000 EST", @ConvertStringToDate(.Date2)+"T000000.000 EST")
I created ConvertStringToDate function to convert string to Date with the following code. It accepts String and returns String.
if(Date!="")
{
try {
Date dtDob = new Date(Date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return sdf.format(dtDob);
} catch (Exception e) {
oLog.error("Issue while parsing date -" + e);
return "";
}
}else
{
return "";
}
Update the timezone based on the business and call the above function in a Validate rule or Activity based on your needs.
I hope it helps you. Let me know if you face any issues with the above.
Good Luck!
Pega Collaboration Center has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.