calculate difference between to date and convert to time

Avatar

Avatar

eugzl

Avatar

eugzl

eugzl

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)

Accepted Solutions (1)

Avatar

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485

Avatar

radzmar

MVP

Total Posts

2.6K

Likes

386

Correct Answer

485
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

Answers (0)