Form designer: How to check if a date value is after another date?

In your form, you have defined two date fields (Date1 and Date2). When the user selects a value for the Date2 field, you want to check if the Date2 value is after the Date1 value.

The solution is to add a custom validation in the Date2 form field settings:

DateTime.Parse(REQUEST_DATE2.Text) > DateTime.Parse(REQUEST_DATE1.Text)

Hello,

How can I check if a date value entered in the field is less or equal to 90 days from today’s date?
That field has to be limited to 90 days or less.

Thank you,

Marina

Hi @marinam,

For 90 days or less, the syntax should look like this:

(DateTime.Parse(REQUEST_DATETIME.Text) - DateTime.Now).TotalDays <= 90 

But if you also want to make sure it’s bigger than 0, it should look like this:

(DateTime.Parse(REQUEST_DATETIME.Text) - DateTime.Now).TotalDays <= 90 && (DateTime.Parse(REQUEST_DATETIME.Text) - DateTime.Now).TotalDays >0

Hope this helps

Thank you Eddy!
Your response was very helpful, as always! :blush:
Marina

1 Like

Hello, I try this : DateTime.Parse(ACTION1_DATE_SOLDE_INITIALE.Text) - DateTime.Now) >= 0 but I have this error message : CS0019: Operator ‘-’ cannot be applied to operands of type ‘string’ and ‘System.DateTime’. Someone can help me?

Hi @ElisaNPP,

Try this:
(DateTime.Parse(ACTION1_DATE_SOLDE_INITIALE.Text) - DateTime.Now).TotalDays >=0