Compute hours and minutes


Q: I have a table where I have a starting and an ending date as well as a starting time and an ending time as fields. How can I compute the number of hours and minutes between start and end? All the four fields are DateTime fields

A. You can do this in a computed field in a question with the following field definition:

TimeElapsed: Round(24 * ([EndDate] + [EndTime] - [StartDate] - [StartTime]), 2)

This will express the interval as hours with two decimals. If you want to have it in hours and minutes, you could use the following two definitions instead:

HoursElapsed: Int(24 * ([EndDate] + [EndTime] - [StartDate] - [StartTime]))

MinutesElapsed: Round(60 * (24 * ([EndDate] + [EndTime] - [StartDate] - [StartTime]) - HoursElapsed), 0)

NOTE: If you use a machine set to Swedish regional options, use ";" instead of ',' wherver it occurs above.

Back