Calculate the number of hours and minutes

I have 3 questions type text,
q1 hour from …time to,
q2 hour from … time to,
q3 hour from … time to.

I need to calculate the number of hours and minutes of the questions, for example:
q1: 08:30 am…09:45am,
q2: 10:45 am…12:45pm,
q3: 15:30 pm…18:30pm.

The result would be 6 hours 15 minutes. What would be the expression I should use?

see around these threads

and possibly others at the forum.

Hi sergiy, I have the following variables:

start hours --> (int.Parse (q1.Left (2)))
start minutes --> (int.Parse (q1.Right (2)))
activity_start --> (new DateTime (2019,1 , start_hours.InRange (0,1)? 2: 1,
(int) start_hours, (int) start_minutes, 0))
finish_hours --> (int.Parse (q1.Left (2)))
finish_minutes --> (int.Parse (q1.Right (2)))
duration --> ((activity_finish-activity_start ) .Value.TotalHours),
duration_str --> ((IsAnswered (duration))
? String.Format ("{0: F2}", duration)
: “#”),
activity_finish --> (new DateTime (2019,1, finish_hours.InRange (0,1)? 2: 1,
(int) finish_hours, (int) finish_minutes, 0)),

and this code to show the calculation of hours and minutes: HORARIO 1: %q1% - %q1% (%duration_str% hrs), however when I enter for example: 03:30 y 04: 55 it should show: 1.25 but it shows: 1.42. Where is the problem?

I don’t understand.

It should show 1.42 and it shows 1.42.

Why do you think there is a problem in the first place?


Hi sergiy
I attach the image, it should show 1.25 (one hour and twenty minutes) not 1.42 (one hour and fourty two minutes.)

Correction, it should show “an hour twenty five minutes” not “an hour fourty two minutes”.

It is not “one hour and forty two minutes” it is “one point forty two hours”.

Why you expect minutes there is a mystery to me. You are using TotalHours property, please read the function description before using it. Another reason to read the documentation is that it has an exact example for the task you are trying to achieve: