Calculate elapsed time

I am using elastic as datasource and having start date coming from one query. I have end date coming from another query. I want to calculate the difference between the 2 dates.

The difference should be reflected in hours.

I see following metrics options

Can it be resolved using Mixed DataSource?

Did you look at the Time Range documentation.

I have the same question, for example if I have a swich which is on and off. I would like to know how much time was on for s specific time. How can I query that ?