Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone !
I'm trying to calculate the total number of hours that fall within a specific time window ( between 00:00 and 06:00 ) across a time range defined by two timestamps in Qlik Sense.
For example, suppose I have the following timestamps :
StartTime: 2025-04-20 22:00:00
EndTime: 2025-04-21 08:00:00
I want to calculate how many hours between these two timestamps fall specifically within the 00:00 to 06:00 window. In this case, the answer should be 6 hours, since the entire window from 00:00 to 06:00 on 2025-04-21 is covered by the interval.
Another example:
StartTime: 2025-04-20 05:00:00
EndTime: 2025-04-20 07:00:00
Here, the overlap with the 00:00–06:00 window is only from 05:00 to 06:00, so the expected result would be 1 hour.
Does anyone know how this kind of calculation can be done in Qlik Sense (script or chart expression) ?
Thanks in advance for your help!
Try this
Interval(Timestamp#('2025-04-21 08:00:00', 'YYYY-MM-DD hh:mm:ss') - Timestamp#('2025-04-20 22:00:00', 'YYYY-MM-DD hh:mm:ss'), 'hh')
I already tried this method , it work great for counting the number of hours between two timestamps but finding the number of hours between the 2 timestamp is not the issue , the real issue is to count the hours only between 00:00 and 06:00
Can you assume that the period will not run over more than a single night? If so then you can do something like this.
Interval(
rangemin(dayname(timestamp_end) + maketime(6) , timestamp_end)
- rangemax(dayname(timestamp_end), timestamp_start)
, 'hh')