Counting number of days in Forms | Community
Skip to main content
June 18, 2025

Counting number of days in Forms

  • June 18, 2025
  • 2 replies
  • 477 views

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. 🙂

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

ButhpurKiran
Level 4
June 18, 2025

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

June 18, 2025

Thank you for that info!!

This is the message I receive when Previewing PDF:

 

Karishma_begumSh
Level 4
June 19, 2025

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.

kautuk_sahni
Community Manager
Community Manager
June 30, 2025

@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