Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Calculate the days between two dates in a third field

Avatar

Level 2

Hi,

I am using Adobe Livecycle Designer ES4.  I am making a travel form for my company.  The form has two date fields “BeginDate” and “EndingDate”.  I would like to calculate the days between the two dates in a third field called “TotalDaysOfTravel”.  I would also like to have something setup that if the employee choses a date in the  “BeginDate” field that is later than the one in the “EndingDate” field that it would give a warning “The ending date is earlier than the beginning date.”  The field should be setup to calculate the “TotalDaysOfTravel” automatically if anything in the two date fields change.

Could someone help me set this up?

Thanks.

1 Reply

Avatar

Level 10

This isn't that complicated.

In the field "TotalDaysOfTravel" add the following FormCalc script in the calculate event:

var datePattern = "MM/DD/YYYY" /if neccessary change the pattern to the format you use to display your dates

var startDate = Date2Num(BeginDate.formattedValue, datePattern)

var endDate = Date2Num(EndingDate.formattedValue, datePattern)

var numOfDays = endDate - startDate +1

$ = numOfDays