# How i can constrain a datefield to be today or 5 days max before?

453
6
06-12-2017 08:03 AM
Occasional Contributor

hi,

Is there someone to help me on constraint with date field.

I've a datefield and i want that the user put a date that would be the d-day or 5 days before the d-day max.

I've tried with : >now() +5*24*60*60*1000, but does not function.

A french guy!

Tags (2)
1 Solution

Accepted Solutions
Esri Esteemed Contributor

Hi Louis,

So the valid dates are from today -5 days?  In that case you would need a compound statement to set lower and upper bounds:

int(.) >= int(today()) - 5*24*60*60*1000 and int(.) <= today(.)

So it must be greater than or equal to 5 days ago and less than or equal to today.

6 Replies
Esri Frequent Contributor

Bon jour Louis.  Attaching an example that worked  for me.

Occasional Contributor

Hi Ismael,

Thank you for your help. I've tried but still does not function

see in the attached video: https://framadrop.org/r/EtNaumkzlh#FgGTNJK0byjyhHCA4dmY7rWSZVYSq28AGj7emVtR+vQ=

Esri Esteemed Contributor

Hi Louis,

There seems to be a type conversion issue causing the problem.  can you try the following constraint:

int(.) < int(today()) + 5*24*60*60*1000

The addition should work correctly with everything being an integer.

Occasional Contributor

Hi James,

Thank you for your answer. I would never find it alone !

It seems to work. But what i wanted to do was to forbidden a date after today and more than 5 days before today

For exemple, we are the 15/06/2017

The user can had 10/06 , 11/06, 12/06, 13/06, 14/06 and 15/06 but not more.

What would be the constrain for that?

Regards

Esri Esteemed Contributor

Hi Louis,

So the valid dates are from today -5 days?  In that case you would need a compound statement to set lower and upper bounds:

int(.) >= int(today()) - 5*24*60*60*1000 and int(.) <= today(.)

So it must be greater than or equal to 5 days ago and less than or equal to today.

Occasional Contributor

PERFECT

THANK YOU VERY MUCH!

It works great