Expand my Community achievements bar.

SOLVED

Conditional statement with calendar field

Avatar

Level 3

Hi,

I need to set a condition on a calendar field (ArrivalDate) that enforces users to only pick certain date from the calendar. Otherwise, it will give them a message and clear the calendar. Also, I need to set up another condition with "in between" but I'm not sure how to set these up.

THANK YOU FOR YOUR HELP!!!

J

1 Accepted Solution

Avatar

Correct answer by
Level 7

For the first one you could do (in formcalc):

if (Date2Num($.formattedValue, "DD/MM/YY") <  41123 and Date2Num($.formattedValue, "DD/MM/YY") <> 0) then

    xfa.host.messageBox("Your arrival date cannot be before 03/08/12", "My message",1)

    $ = ""

endif

you need to make sure you set the input pattern to be DD/MM/YY or whatever you are using in the code above so it matches.

For the second one you could do:

if (Date2Num($.formattedValue, "DD/MM/YY") > 41130 and Date2Num($.formattedValue, "DD/MM/YY") <> 0) then

    xfa.host.messageBox("Your departure date cannot be after 10/08/12", "My message",1)

    $ = ""

endif

View solution in original post

5 Replies

Avatar

Level 7

You can use the function Date2Num. It turns dates into numbers so you can specify in the exit event of the calendar which actual dates (as numbers) can be excepted and if they put in a different date you can clear it.

Avatar

Level 3

Hi,

Thank you for your reply. I'm not familar with the Date2Num function and I'm not 100% sure how to write the sintax. Would you mind helping me? What I need is to write a code that will prevent users from picking a date before Aug 03, 2012. And I also have another date field where I have to apply the same restriction scenario but also need to prevent them to pick a day past Aug 10, 2012.

Thank you very much for your help!!!!

J

Avatar

Correct answer by
Level 7

For the first one you could do (in formcalc):

if (Date2Num($.formattedValue, "DD/MM/YY") <  41123 and Date2Num($.formattedValue, "DD/MM/YY") <> 0) then

    xfa.host.messageBox("Your arrival date cannot be before 03/08/12", "My message",1)

    $ = ""

endif

you need to make sure you set the input pattern to be DD/MM/YY or whatever you are using in the code above so it matches.

For the second one you could do:

if (Date2Num($.formattedValue, "DD/MM/YY") > 41130 and Date2Num($.formattedValue, "DD/MM/YY") <> 0) then

    xfa.host.messageBox("Your departure date cannot be after 10/08/12", "My message",1)

    $ = ""

endif

Avatar

Level 3

Hi,

Thank you very much!! it works great!! I do have one more question though, How do you know that the value "41123" is equal to August 3, 2012? I tried to figured out but I couldn't... I just want to know so I can apply it to any date....

Thanks a billion!!!

Avatar

Level 7

You can just make a textfield to test any date.. just put in the calculation event (in formcalc):

$ = Date2Num("03/08/12", "DD/MM/YY")

or whatever date you want and when you preview the form it will give you the number.