Search code examples
adobelivecyclelivecycle-designer

FormCalc Date function Adobe LiveCycle


I have two fields (1) start date and (2) end date in a PDF form. I would like a message to appear if the user selects a date that is not between specific dates. For instance, if a user does not select a date that is ">01/01/2014 AND <01/01/2015" I have tried the following code but with no success. I'm using 'FormCalc' on the 'Exit' event.

var selectedNum = Date2Num($.rawValue, "YYYY-MM-DD")
    if ( selectedNum >01/01/2014AND<01/01/2015) then
    xfa.host.messageBox("Please enter a date for 2014.")
    xfa.host.setFocus("DateTimeField1")

endif

Solution

  • You can try the following code.

     var selectedNum = Date2Num($.rawValue, "YYYY-MM-DD")
     if (  (selectedNum<41639)OR (selectedNum>42004)) then
        xfa.host.messageBox("Please enter a date for 2014.")
        xfa.host.setFocus("DateTimeField1")
     endif
    

    Date2Num function according to documentation link.

    Returns the number of days since the epoch, given a date string.

    that means that in comparison you should also use numbers.

    • 41639 represents 01/01/2014
    • 42004 represents 01/01/2015