0

# Calculating hours from Appointment

I bet there's a better way of doing this:

``````
if text(duration(Appointment)) > "2:00" then
"More than two hours"
else
if text(duration(Appointment)) > "1:00" then
"Two hours"
else
if text(duration(Appointment)) = "1:00" then
"One hour"
end
end
end
end
``````

I thought saying if text(duration(Appointment)) > "1:00" and ≤ "2:00" that would be better but I can't figure out how to write that.

I'm trying to bill by the hour so even if the appointment is 1:30 the answer should be "Two hours".

Or should I stick with my longwinded code?!

Thanks

## 3replies

• Fred
• 4 mths ago
• Reported - view

May I recommend another way. You can use the ceil() command. It would look something like:

``````let x := number(duration(Appointment) / 3600000);
ceil(x)
``````

In Ninox, time is kept in milliseconds. There is 3,600,000 milliseconds in an hour.

So on line 1, we take our duration() time and divide by 3600000. Then we convert that result into a simple number. Otherwise Ninox continues to treat the result as time.

Then in line 2 we use the ceil() command to tell Ninox to always round up the results of line 1.

I don't know how exact you track the appointments, but a limitation is that even 1 minute over 1 hour will push the result to 2.

• Davie
• 4 mths ago
• Reported - view

Thanks, I'll use that.
For billing anywhere between one and eight hours I still need eight nested if - else statements. I wonder if there's a more efficient way of doing that.

Supplementary: Can I add notes to my code? Is there a special symbol to escape the code for a couple of lines?

• John_Halls
• 4 mths ago
• Reported - view

I would use the Switch - Case structure, as shown here

https://forum.ninox.com/t/q6hdmzw/switch-case-statement-in-ninox

Regards John

## Content aside

• 4 mths agoLast active
• 3Replies
• 52Views
• 3 Following