Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Mission!

Learn More

View all

Sign in to view all badges

# Adobe LiveCycle (Archived)

## calculate difference between to date and convert to time

eugzl
Level 2

Likes

5 likes

Total Posts

171 posts

Correct Reply

5 solutions
Top badges earned
View profile

eugzl
Level 2

Likes

5 likes

Total Posts

171 posts

Correct Reply

5 solutions
Top badges earned
View profile
eugzl
Level 2

31-10-2018

Hi All

I try to calculate in FormCalc difference between to dates and display result in time format like HH:MM.

I have two date fields formatted by MM/DD/YYYY: satrtDate and endDate. And TextFeild where I expect to get result.

My code for TextField in calculate event:

`differenceD = (Date2Num(endDate, "YYYY-MM-DD") - Date2Num(startDate, "YYYY-MM-DD")) * (1000 * 60 * 60 * 24)\$ = Num2GMTime(differenceD, "HH:MM")`

But unfortunately I cannot get the result. What is problem in my calculation? How to fix to calculate correctly?

Thanks.

#### Accepted Solutions (1)

radzmar
MVP

Likes

394 likes

Total Posts

2,686 posts

Correct Reply

490 solutions
Top badges earned
View profile

radzmar
MVP

Likes

394 likes

Total Posts

2,686 posts

Correct Reply

490 solutions
Top badges earned
View profile
radzmar
MVP

03-11-2018

Well, as a day only has 24 hours, you cannot use the Num2Time() or Num2GMTime() methods. They can only handle the amount of milliseconds within a 24 hour time frame.

For your scenario you better use a numeric field with the following display pattern:

To calculate the difference use this FormCalc script:

`\$ = (Date2Num(endDate.formattedValue, "YYYY-MM-DD") - Date2Num(startDate.formattedValue, "YYYY-MM-DD")) * 24`