Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

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

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

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

4 Replies

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

Level 3

Awesome formula and easy to use.

Thanks a million.

Arnold Love

Level 7

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

Thanks

Level 10

Hi,