Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

2 Calendar dates and a day count calculated on 1 form.

Avatar

Level 3

Hello forum,

I makin a new form that has two calendar dates.

The first date is a start date

The second is an end date

After the dates are selected a text box will generate the number of days.

How could I accomplish this.

I'm desperate for help, my form is ready for presentation and I've tried to find a solution and I'm at my deadline.

Thank You so much forum!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I would recommend using FormCalc for anything to do with dates. The process is fairly straight forward, you convert each date to a number and subtract them. In the script I have wrapped the calculation in an if statement to check that the dates are correct first:

if (startDate == null or finishDate == null ) then

     $ = null

elseif (startDate > finishDate) then

     xfa.host.messageBox("Please check the start and finish dates, as there appears to be an error", "Dates")

     $ = null

else

     $ = Date2Num(finishDate, "YYYY-MM-DD", "en_IE") - Date2Num(startDate, "YYYY-MM-DD", "en_IE")

endif

Good luck with the presentation,

Niall

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

I would recommend using FormCalc for anything to do with dates. The process is fairly straight forward, you convert each date to a number and subtract them. In the script I have wrapped the calculation in an if statement to check that the dates are correct first:

if (startDate == null or finishDate == null ) then

     $ = null

elseif (startDate > finishDate) then

     xfa.host.messageBox("Please check the start and finish dates, as there appears to be an error", "Dates")

     $ = null

else

     $ = Date2Num(finishDate, "YYYY-MM-DD", "en_IE") - Date2Num(startDate, "YYYY-MM-DD", "en_IE")

endif

Good luck with the presentation,

Niall

Avatar

Level 3

Awesome formula and easy to use.

Thanks a million.


Arnold Love

Avatar

Level 7

There is any way the script does not calculate Saturdays and Sundays?

Thanks

Avatar

Level 10

Hi,

There may be something here, that may help you.

Good luck,

Niall