Date Validation on If Condition

Date Validation on If Condition

  

Hi

Need to validate the date on input widget should be 18 years ago before current date

any idea how to do it on if condition?


Thank you so much

you can check in an if:

date < AddYears(CurrDate(), -18)


Hi Mark, 

The easiest way to do input validation is using the native features for that.

Please check the documentaion on https://success.outsystems.com/Documentation/10/Developing_an_Application/Design_UI/Forms/Validate_Form_Inputs

and this lesson https://www.outsystems.com/learn/lesson/857/input-validation/


In your case you will combine the examples in this material with BuiltIn Function DiffDays(Date1,Date2)  that returns the number of the days between 2 dates.  



Best regards

Fabio Fantato



Solution

Hello mark

You can use AddYears and pass CurrDate() and -18 as the input parameters. It will return a date that is 18 years before the current date.

the comparison would be

MyDateTime <= AddYears(CurrDate(), -18)

https://success.outsystems.com/Documentation/10/Reference/Logic/Built-in_Functions/Date_and_Time_Built-in_Functions#AddYears

AddYears returns a DateTime. If you will compare against a date, need to convert to date using DateTimeToDate.

Cheers

EDIT. I was slow, lol ;)

Solution

Hi Martin

Thank you so much for your response but its not working

I try these two:

SyntaxEditor Code Snippet

CurrDate(EmployeeStructureForm.Record.Birthdate) < AddYears(CurrDate(), -18)


SyntaxEditor Code Snippet

EmployeeStructureForm.Record.Birthdate < AddYears(CurrDate(), -18)

Mark Anthony Gonzales wrote:


EmployeeStructureForm.Record.Birthdate < DateTimeToDate(AddYears(CurrDate(), -18))

If Birthdate is a DATE, need to convert the result of AddYears to Date.


Eduardo Jauch wrote:

Mark Anthony Gonzales wrote:


EmployeeStructureForm.Record.Birthdate < DateTimeToDate(AddYears(CurrDate(), -18))

If Birthdate is a DATE, need to convert the result of AddYears to Date.


Hi Eduardo,

Thank you so much, its now working

Mark