Expand my Community achievements bar.

Join expert-led, customer-led sessions on Adobe Experience Manager Assets on August 20th at our Skill Exchange.

Counting number of days in Forms

Avatar

Level 1

Hi, I'm new to Designer, and I use the Forms part only. I'm looking for how to have a Numeric Field show a calculation of days. The form has two date/time fields and I want my Numeric Field to show how many days.

 

I'm reading through the FormCalc and am having a lot of trouble. Thank you to anyone that can help.

4 Replies

Avatar

Level 4

Hi,

 

Assuming you already have 2(DateField1 & DateField2) date fields and a num(DaysDifference) field,

 

- Navigate to the Exit event of DateField2 (or use the Calculate event of DaysDifference).

- Select FormCalc for Scripting language

 

if (DateField1.rawValue ne null and DateField2.rawValue ne null) then
  DaysDifference.rawValue = 
    Date2Num(DateField1, "YYYY-MM-DD") - Date2Num(DateField2, "YYYY-MM-DD")
else
  DaysDifference.rawValue = ""
endif

 

PS: you may need to maintain same format as of code. Alternatively, you can make relevant changes in code.

 

Hope this helps.

 

Kind regards,

Kiran Buthpur

Avatar

Level 1

Thank you for that info!!

This is the message I receive when Previewing PDF:

DominiqueLo1_0-1750286563243.png

 

Avatar

Level 4

hi @DominiqueLo1 

The overall approach is valid — it checks if both date fields have values and calculates the difference using Date2Num(). However, it throws an error because rawValue is being accessed on unknown or incorrect field names.

Suggested Fix:

  • Confirm that the field names (DateField1, DateField2, DaysDifference) match exactly in the form.
  • Use the Calculate event of the DaysDifference numeric field (rather than Exit), as it automatically updates when either date changes.
  • Use HasValue() and formattedValue to safely reference date fields.
if (HasValue(DateField1) and HasValue(DateField2)) then
  Date2Num(DateField2.formattedValue, "YYYY-MM-DD") - Date2Num(DateField1.formattedValue, "YYYY-MM-DD")
else
  ""
endif

 Regards,

Karishma.

Avatar

Administrator

@DominiqueLo1 Just checking in — were you able to resolve your issue?
We’d love to hear how things worked out. If the suggestions above helped, marking a response as correct can guide others with similar questions. And if you found another solution, feel free to share it — your insights could really benefit the community. Thanks again for being part of the conversation!



Kautuk Sahni