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:

1 Like

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:

I am trying to wrap my head around this one so I can find out if todays date falls between 2 weeks after a starting date and 2 months after the same starting date. :crazy_face:

@Brad_Hedinger

Here's one way to do it:

{note: trim=right; preview=no}
{startingdate={time: X; at={=date}; pattern=M/D/YYYY}}
{date1={time: X; at={=date}; pattern=M/D/YYYY; shift=+2W<D}}
{date2={time: X; at={=date}; pattern=M/D/YYYY; shift=+2M>D}}
{endnote: trim=right}

{note: trim=right}
Starting date: {formtext: name=date; default={time: M/D/YYYY; shift=-2W}} ({time: dddd, MMMM Do, YYYY; at={=date}; pattern=M/D/YYYY})

{endnote: trim=right}

{time: dddd, MMMM Do, YYYY} (today) {if: {time: X} >= date1 AND {time: X} <= date2}falls{else}does not fall{endif} between {time: dddd, MMMM Do, YYYY; at={=date1}; pattern=X} and {time: dddd, MMMM Do, YYYY; at={=date2}; pattern=X}.

The best way to approach a problem like this is always to break it down into the basic required elements, i.e.

  • today's date
  • the starting date
  • the date 2 weeks after starting
  • the date 2 months after starting

Then you need to build the logic one step at a time.

Hope this helps :slight_smile:

1 Like

Ohhhh! I see where you are going with that! Now, let's say that the starting date is not a form field, but a date in M/D/YYYY format that is pulled into the snippet via regex?

Hi @Brad_Hedinger,

No need. Just make a text field instead of the date picker, give it the same label, and change the pattern setting to the date format you want to recognize.

I've updated the example in the other post.

I’m a little unclear @Cedric_Debono_Blaze. I need the date field to be pulled in via regex because that date is different for every student record and it is what drives the rest of the snippet logic. I could easily use the site selector and name the field but in Salesforce Lightning, site selector is incredibly unreliable because if multiple tabs are open in salesforce, it throws off the selectors. Any thoughts?

Hi @Brad_Hedinger,

Did you see the updated version of the snippet in the post further up? I've changed the date selector to a regular text field that accepts dates in the format you specified. Since Salesforce selectors are a bit tricky, you could just copy the date and use the {clipboard} command as the default for the text field.

Does that make sense? Or am I off track?

That makes perfect sense. Thank you! However, I do not want the user to have to copy/paste data into that field. When they run this snippet, it needs to pull in the date automatically (I imagine via Regex), then use that value to drive date shifters. Here is the direction we have in plain text that I am trying to automate with TB:

Assign Task Per Below:
• 2 weeks-2 months after start date (Campus) / 1 month-2months after start date (Online): Dahly Jimenez
• VA COE (VA FA COE process and first 30 days after start): Lady Marcellus
Otherwise...
• Campus VA Students (A-Z): Armand Izzo
• Online VA Students (A-F): Reggis Metayer
• Online VA Students (G-O): Dahly Jimenez
• Online VA Students (P-Z): Vien Le (Delgado)

Hi @Brad_Hedinger,

Let's jump on a call :slight_smile: You have me email.

1 Like