Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
gleybson
Partner - Contributor II
Partner - Contributor II

How to calculate hours in date range

 

I have several notes that start one day and end the next. I need to calculate and the rule is start greater than 16h and end less than 16h.
Example:
func, oper, dt ini time, dt end time,
A, 1, 06/26/2022 22:00, 06/26/2022 22:50
A, 2, 06/27/2022 01:00, 06/27/2022 04:30
A, 3, 06/27/2022 17:00, 06/27/2022 22:00
A, 4, 06/28/2022 20:00, 06/28/2022 23:00
A, 5, 06/29/2022 03:00, 06/29/2022 14:00
B, 1, 06/26/2022 22:00, 06/26/2022 22:50
B, 2, 06/27/2022 01:00, 06/27/2022 04:30
B, 3, 06/27/2022 17:00, 06/27/2022 22:00
B, 4, 06/28/2022 20:00, 06/28/2022 23:00
B, 5, 06/29/2022 03:00, 06/29/2022 14:00

Desired result:
Func "A" on the 26th = from 22:00 on the 26th to 04:30 on the 27th
func, day, total hours
A, 26 06:30
A, 27 05:00
A, 28 18:00

Labels (1)
2 Replies
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Hi,

 

I have tryed this :

 

Data:
Load
*,
If(Hour([dt ini time]) <=16, 1, 0) as Flg_ini,
If(Hour([dt ini time]) >=16, 1, 0) as Flg_end
;
Load
func,
oper,
Timestamp#([dt ini time], 'MM/DD/YYYY hh:mm') as [dt ini time],
Timestamp#([dt end time], 'MM/DD/YYYY hh:mm') as [dt end time]
Inline [
func, oper, dt ini time, dt end time,
A, 1, 06/26/2022 22:00, 06/26/2022 22:50
A, 2, 06/27/2022 01:00, 06/27/2022 04:30
A, 3, 06/27/2022 17:00, 06/27/2022 22:00
A, 4, 06/28/2022 20:00, 06/28/2022 23:00
A, 5, 06/29/2022 03:00, 06/29/2022 14:00
B, 1, 06/26/2022 22:00, 06/26/2022 22:50
B, 2, 06/27/2022 01:00, 06/27/2022 04:30
B, 3, 06/27/2022 17:00, 06/27/2022 22:00
B, 4, 06/28/2022 20:00, 06/28/2022 23:00
B, 5, 06/29/2022 03:00, 06/29/2022 14:00
];


Load
*,
If(Peek(Flg_ini)=1 and Flg_end=1,
Peek([dt ini time])
) as toto
Resident Data
Order By
func,
[dt ini time] desc
;

Drop Table Data;

 

amartinez35_0-1660319970182.png

 

Aurélien

 

Help users find answers! Don't forget to mark a solution that worked for you!
gleybson
Partner - Contributor II
Partner - Contributor II
Author

What does this "toto" field mean?