Find duration between 2 fields with data type (Time of day) ?

  • 0
  • 1
  • Question
  • Updated 11 months ago
  • Answered
How to find duration when start date field is of type (Time of day) and end date field is of type (time of day). I need to find the total duration between start date and end date in terms of days and hours.
Photo of Raj Helaiya

Raj Helaiya

  • 1,246 Points 1k badge 2x thumb

Posted 11 months ago

  • 0
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,166 Points 50k badge 2x thumb
There is not enough information to be able to do that calculation, since we do not know the day of the start and the stop.

You need to record the start date and the start time and the end date and the end time.  That can be done either with 4 fields or two fields of type "date/time".
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,352 Points 20k badge 2x thumb
ToDays([tod2] - [tod1]) will return a number as fraction of a day. 

ToHours([tod2] - [tod1]) will return the number of integer hours and a decimal representing the fraction of hours.

(Edited)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,166 Points 50k badge 2x thumb
... assuming that all data entry is done on the same day and does not cross midnight.

I was confused because Raj said "in terms of days and hours."
Photo of Raj Helaiya

Raj Helaiya

  • 1,246 Points 1k badge 2x thumb
Do you mean the start date and end date should be same day? My use case is something like this:

Start date can be 1st dec and end date can be 5th dec. Also I need to know the time of start day and end day so I can display a result. For example: "Outage Duratio" was 4 days and 7 hours. Can this be achieved?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,166 Points 50k badge 2x thumb
Yes no problem, but let me know what you are fields are which are capturing the start date and end date.  i suggest that you make fields for those and btw, a user tip is that if you type a T into a date field it will populate to today.

So you may want to default the start date to the current day and then users will type a T to set the date when the ticket is closed, as well as the time.  or else you can have a form rule to check a checkbox that will set the  end date to today and the end time to now.
Photo of Raj Helaiya

Raj Helaiya

  • 1,246 Points 1k badge 2x thumb
Thank you for your help, I tweaked my field types and was able to find the solution in "Days Format". 
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,352 Points 20k badge 2x thumb
I was confused because I answered a question without using JavaScript. Its gonna be a bad day - we have 7 inches of snow coming ...