Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

Not applicable
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"It cannot be before the Start date!", "Date Checker", 3)

$.rawValue = "" (xfa.form.form1.DateTimeNeeded)


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

if (DateTimeNeeded.rawValue = DateTimeRequested.rawValue ) then ("Please contact Abdi since you're requesting same day")

$.rawValue = ""



3 Replies
Level 7
Level 7
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.
Not applicable
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.
Level 7
Level 7
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, "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.