Date Picker Validation

Hey there, was attempting to validate the entry of a date selection in a form. I want to present an error if the date entered is over 60 days old. But I’m getting an error of "Cannot convert "date" to a number.".

Wondering if anyone can point out what I’m doing wrong here:

{formdate: MM/DD/YYYY; name=OpenDate}{if: OpenDate > {time: MM/DD/YYYY; shift=60D}}{error: Date is older than 60 days; block=yes}{else}{endif}

I’m guessing it has to do with the slashes in the date. Is there a better way to validate the date is older than 60 days?

Hi @Peter_Monterubio,

You can do that by using the Unix Timestamp X, which gives you the time in seconds.

{formdate: MM/DD/YYYY; name=OpenDate}{if: {={={time: X}/60/60/24}-{time: X; at={=OpenDate}; pattern=MM/DD/YYYY}/60/60/24}>60}{error: Date is older than 60 days; block=yes}{else}{endif}

To explain what I did:

  1. I converted the OpenDate variable to Unix Timestamp
  2. I converted the current date to Unix Timestamp
  3. I divided both numbers by 60 to get minutes then again by 60 to get hours, then by 24 to get days
  4. I subtracted the smaller number from the bigger and checked whether it exceeded 60
  5. Then I continued with the rest of the commands that you created

Hope this helps :slight_smile:

Holy cow! You are a life saver! This is amazing!

:grin:

Ok, so now you owe me! :stuck_out_tongue_winking_eye:

Check out this thread. I'm expecting a good challenge from you: