# Complex Date Validations Made Simple

Here is the scenario:
“On your DatePicker, I desperately need the ability to have a start and end date picker, that I can set a value of Today + n days as the max date for StartDate, and then on the Endate + y days for a max on the EndDate.”

Example
1st Jan 2010 Is Today
StartDate: Max Start Date would be Today + N where N is 350 days.

EndDate: Beginning Date would be Startdate, Max for EndDate would be StartDate + Y. Where Y is 15 days.

So: 30th Dec 2010 would be OK as start date, and end date could be up to 14 Jan 2011.

How to do this in Simfatic Forms?

## 1. Add the Date Picker fields

First, add the date picker fields and name them as StartDate and EndDate. ## 2. Add a calculation field DateDiffFromToday

We need to find out the days between today (the day on which the form is filled out) and the start date. Add a calculation field and name it say, DateDiffFromToday. We can use the calculation function `days_from_today()` .
The formula is:
`days_from_today(StartDate)` ## 2. Add another calculation field DateDiff

We need to find the number of days between StartDate and EndDate. Add a calculation field DateDiff and use the function days_between() in the formula.
Formula:
days_between(Enddate, StartDate) We can make the calculation fields hidden if the value need not be shown to the user. ## 3. Validations

First, StartDate should be after Today. Similarly, we can validate the EndDate to be after StartDate.

The StartDate should be within 350 days from the day the form is filled in. So the value of DateDiffFromToday (the calculation field) should be less than 350, but greater than 0. The days between StartDate and EndDate should be less than 15.

Putting it together, we have all the validations this way: Tags ↓