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
BedrockMission!

Learn More

View all

Sign in to view all badges

calculate difference between to date and convert to time

Avatar

Avatar
Validate 10
Level 2
eugzl
Level 2

Likes

5 likes

Total Posts

171 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Validate 10
Level 2
eugzl
Level 2

Likes

5 likes

Total Posts

171 posts

Correct Reply

5 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
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)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
radzmar
MVP

Likes

394 likes

Total Posts

2,686 posts

Correct Reply

490 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile

Avatar
Coach
MVP
radzmar
MVP

Likes

394 likes

Total Posts

2,686 posts

Correct Reply

490 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
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

Answers (0)