3988
Views
9
Comments
Solved
Date Validation on If Condition
Question

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

2020-02-28 09-46-54
Eduardo Jauch
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 ;)

2020-06-02 12-03-59
Martin den Braven

you can check in an if:

date < AddYears(CurrDate(), -18)


2026-03-09 12-26-51
Fábio Fantato
 
MVP

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



2020-02-28 09-46-54
Eduardo Jauch
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 ;)

UserImage.jpg
Mark Anthony Gonzales

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)
2020-02-28 09-46-54
Eduardo Jauch

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.


UserImage.jpg
Mark Anthony Gonzales

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


UserImage.jpg
Sandeep Khare

I want to display DD-MM-YYY instead of 01-01-1900 if date is null.

Please suggest

2026-02-05 15-36-36
Lenon Manhães Villeth
Champion

Sandeep Khare wrote:

I want to display DD-MM-YYY instead of 01-01-1900 if date is null.

Please suggest

In this case, your database won't record the value "YYYY-MM-DD", so you must format the expression on the screen to show "YYYY-MM-DD" when the date is null. Try the following expression:

If (YourEntity.Atributte.Date) = NullDate(), "YYYY-MM-DD" , YourEntity.Atributte.Date)


2019-11-04 12-49-52
Ivan Cássio Balbino Dias Amaral

Mark Anthony Gonzales wrote:

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 try (Currdate -18 = true OR Currdate <>18 = false)


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.