Expand my Community achievements bar.

Using Formcalc to calculate Days between Dates

Avatar

Former Community Member

Sorry to keep reposting this.  For some reason, when I click "Reply" to your earlier messages, nothing happens.  I tried the formula, but keep getting an error on the line with form1.sf1.NumericField2, etc.

Should NumericField2 be the name of my numeric field?  How do I set up that field to receive the data?

5 Replies

Avatar

Employee

Yes, you got it right. NumericField2 is the field in which you would get the number of days. You just need to add this field to your form and no need to set it up. Just write a script which fills in the value of "number of days" in this field. Here's the full explanation.

Let's say you have two DateTime fields in the form namely DateField1 and DateField2. You want to capture the number of days in a numeric field[placed in the form] named NumericField2. To get the number of days as soon as the user fills in date in field DateFiled2 and exits from this field, you need to the write the following formcalc script on exit event of DateField2.

// form1.sf1.DateField2::exit - (FormCalc, client)

   

form1.sf1.NumericField2.rawValue = Date2Num(DateField1, "YYYY-MM-DD") - Date2Num(DateField2, "YYYY-MM-DD");

Hope this solves your query.

Avatar

Former Community Member

It seems like it should be so simple, but I'm obviously missing a step, and this is the first time I've worked with LiveCycle or FormCalc. The error is that form1sf.Numdays.rawValue is unknown.

Could it have something to do with the way the numeric (target) field is set up? I had tried placing the calculation there, but now I'm placing it in the second date field, as you suggested. What value should be assigned to the numeric field?

Also, could I be having trouble because of the date fields Validation Patterns? I changed all of the patterns to MM/DD/YYYY, but still no luck. I must be doing something wrong

Avatar

Former Community Member

I think I found the problem. I renamed Subform (Page) 1 to "sf1" to make this work! Thank you for your help!

Avatar

Employee

That's good to know. Yes, I didn't specify the subform name change. I would recommend you to go through the scripting documentation of Designer. You would find that useful.

http://helpx.adobe.com/livecycle/topics/livecycle-designer.html