Highlighted

Script is throwing error - Comparing two dates (start/end dates)

Avatar

Guest

28-10-2008

I do have two fields (dateRequested - start date & dateNeeded - end

date) and I need to basically test to make sure that End date is not

before the Start date. Also, I want to make sure if they are same

date, they got this message " Contact Abdi".



I am getting this error message: "Syntax error near token "=" Line 7

Column 32.



========================================================================

if(DateTimeNeeded.rawValue <> null and DateTimeRequested.rawValue <> null)

then if(DateTimeNeeded.rawValue < DateTimeRequested.rawValue) then

xfa.host.messageBox("It cannot be before the Start date!", "Date Checker", 3)

$.rawValue = ""

xfa.host.setFocus (xfa.form.form1.DateTimeNeeded)

endif



//This is where I think is the problem..




if (DateTimeNeeded.rawValue = DateTimeRequested.rawValue ) then

xfa.host.messageBox ("Please contact Abdi since you're requesting same day")

$.rawValue = ""

xfa.host.setFocus(xfa.form.form1.DateTimeNeeded)

endif



endif



========================================================================

Replies

Highlighted

gkaiseril

29-10-2008

The "=" is not the equality operator in FormCalc or JavaScirpt, it is the set operator. You have to use "==" or "eq"



You also might want to convert the date time raw value character strings to the number of days from the Epoch date for LiveCycle Designer before doing a comparison. This would convert all dates to a known data type and would be in a common denominator.
Highlighted

Avatar

Guest

29-10-2008

Hi Geo,

Thanks for pointing out that equality operator. I found out that later on. I am really new to the Designer & I would apperciate if you can tell me how to convert the Date time raw value character strings to the number of days from Epoch date.



Thank you.
Highlighted

gkaiseril

30-10-2008

With your date fields with a display format of "MMM DD, YYYY", you can place the following script in the "DateTimeRequested" field's exit event:



var msg = Concat("DateTimeRequested.rawValue = ", DateTimeRequested.rawValue, "\u000a")

var RequestedRV = Date2Num(DateTimeRequested.rawValue)

msg = Concat(msg, "Date2Num(DateTimeRequested.rawValue) = ", RequestedRV, "\u000a")

var RequestedFV = Date2Num(DateTimeRequested.formattedValue, "MMM DD, YYYY")

msg = Concat(msg, "Date2Num(DateTimeRequested.formattedValue, 'MMM DD, YYYY') = ", RequestedFV , "\u000a \u000a" )



msg = Concat(msg, "DateTimeNeeded.rawValue = ", DateTimeNeeded.rawValue, "\u000a")

var NeededRV = Date2Num(DateTimeNeeded.rawValue)

msg = Concat(msg, "Date2Num(DateTimeNeeded.rawValue) = ", NeededRV, "\u000a")

var NeededFV = Date2Num(DateTimeNeeded.formattedValue, "MMM DD, YYYY")

msg = Concat(msg, "Date2Num(DateTimeNeeded.formattedValue, 'MMM DD, YYYY') = ", NeededFV, "\u000a \u000a" )



var Diff = NeededFV - RequestedFV

xfa.host.messageBox(Concat(msg, "Difference in days: ", Diff), "Difference in Days", 1)



When you fill in both dates and exit the needed field you will get a pop-up showing the results.



Note: it is best to set the "Display Pattern" and use the same pattern for the "format" parameter in the Date2Num funciton as this is a value that you can control and know will be correct for the conversion.