How to calculate the minutes between startTime and endTime

Certified Senior Developer

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.

  Discussion posts and replies are publicly visible

Parents
  • 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.

Reply
  • 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.

Children