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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
ahmed_qlik
Partner - Contributor III
Partner - Contributor III

Duration between two timestamps for each day

Hi

I have to calculate Duration spend by vessel on berth based on vessel arrival and departure ( both are in timestamp format ) on Daily basis . 

Sample Input :

vesselarrivaldeparture
A2/2/21 23:302/3/21 23:30
B2/1/21 22:002/2/21 0:30
C2/1/21 23:002/4/21 5:00

 

Expected Output:

DateDuration
1-Feb-213 hours
2-Feb-2125  hour
3-Feb-2147 hours 30 minutes
4-Feb-215 hours

 

Thanks in advance.

 

@sunny_talwar @swuehl @hic @Michael_Tarallo 

Regards

Ahmed

 

7 Replies
Saravanan_Desingh

Sorry, I can't understand. Can you explain me more? How did u get the Duration values?

Ksrinivasan
Specialist
Specialist

hi,

your sample result also wrong,

your time format in MM/DD/YYYY HH:MM'

Ksrinivasan_0-1613107412709.png

ksrinivasan

 

ahmed_qlik
Partner - Contributor III
Partner - Contributor III
Author

Hi

 

I can't understand how it is wrong... it is just sample data .

Yes, My date format is " MM/DD/YYYY hh:mm" . 

ahmed_qlik
Partner - Contributor III
Partner - Contributor III
Author

Hi

I have calculated Duration values manually.

For eg. if you see, on 1st feb, Vessel B was on berth between 

B2/1/21 22:002/2/21 0:30

which means 2 hours should be consider for 1st feb and 30 minutes for 2nd-Feb. 

Same way, Vessel C was on berth between 

C2/1/21 23:002/4/21 5:00

which means 1 hour for 1st feb and 24 hours for2nd-Feb and24 hours for 3rd-Feb and5 hours for 4th-Feb.

So , total hours for 1st feb is (2+1) i,e 3 hours.

 

Hope I am able to explain the scenario.

 

 

Regards

M.A

Saravanan_Desingh

Try this,

tab1:
LOAD * INLINE [
    vessel, arrival, departure
    A, 2/2/21 23:30, 2/3/21 23:30
    B, 2/1/21 22:00, 2/2/21 0:30
    C, 2/1/21 23:00, 2/4/21 5:00
];

Left Join(tab1)
LOAD *, Timestamp(Timestamp#(arrival,'M/D/YY hh:mm')+((IterNo()-1)/1440),'M/D/YY hh:mm') As Duration,
1 As Counter
Resident tab1
While Timestamp#(arrival,'M/D/YY hh:mm')+((IterNo()-1)/1440) <= Timestamp#(departure,'M/D/YY hh:mm');

Left Join(tab1)
LOAD *, Date(Floor(Duration)) As DtCounter
Resident tab1;
Saravanan_Desingh

Output:

commQV94.PNG