Skip to main content
natashan0002
May 15, 2021
Question

How to calculate the minutes between startTime and endTime

  • May 15, 2021
  • 4 replies
  • 0 views

HI,

I am working on a daily log kind of project.

So i need to

1. Take the start time and end time and calculate the number of minutes between them.

eg. 6:15 am  to 8:15 am -> 120 minutes.

I tried using the function 

minute( todatetime(endTime)-todatetime(startTime) )

but this works only till 60 minutes. i.e. 6:15 am to 7:15 am ->0 min.  Should give 60 mins

Also

2. is there any way i can only take the time as input? I have to use a!dateTimeField() Where as i dont want to get concerned with date. 

Once the datetime is entered, i can use totime to get only the time. But i want the input itself to be time and not datetime.

4 replies

danny.verb
May 15, 2021

1. You need to use the function tointervalds()

a!localVariables(
  local!times: totime({"5:00 pm","7:22 pm"}),
  local!difference: tointervalds(local!times[2]) - tointervalds(local!times[1]),
  local!hours: hour(local!difference),
  local!minutes: minute(local!difference),
  (local!hours*60)+local!minutes&" minutes"
)

2. Simplest thing to do would be creating your own dropdown for time where each option is a text value in the format "hh:mm pm" because you can then do totime("5:00 pm") to convert the string to a Time. You can even put the dropdown field in a sidebyside layout to make the dropdown width more narrow.

natashan0002
May 22, 2021

Hello Dany Verb,

Works!! Thank You. [emoticon:c4563cd7d5574777a71c318021cbbcc8]

February 6, 2023

(END TIME - START TIME)*1440
Since a day has 1440 (24*60) minutes, we multiply the result by 1440 to get the exact number of minutes.

Regards,

Rachel Gomez