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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
qw_johan
Creator
Creator

Calculate hours between time intervals

Hi

I need to calculate how many hours there are between a persons work shifts in a

schedule, his "resting time" so to speak.

My table is simple: id_number, timestamp_from, timestamp_to.

My code so far...

LOAD

     id_number,

     timestamp_from,

     timestamp_to,

     Interval(Previous(timestamp_to) - timestamp_from, 'hh:mm') as rest_time

FROM ....

Problem...

The resulting hours in rest_time is a negative number...how to make it into a positive number?

Thanks

1 Solution

Accepted Solutions
jagan
Partner - Champion III
Partner - Champion III

Hi,

Just change from and to column positions in Load script..

LOAD

     id_number,

     timestamp_from,

     timestamp_to,

     Interval(timestamp_from - Previous(timestamp_to) , 'hh:mm') as rest_time

FROM ....

Regards,

Jagan.

View solution in original post

6 Replies
kumarnatarajan
Partner - Specialist
Partner - Specialist

Hi,

Use Fabs() function for positive.

But check your timestamp fields format Interval() function will return correct hours.

jagan
Partner - Champion III
Partner - Champion III

Hi,

Just change from and to column positions in Load script..

LOAD

     id_number,

     timestamp_from,

     timestamp_to,

     Interval(timestamp_from - Previous(timestamp_to) , 'hh:mm') as rest_time

FROM ....

Regards,

Jagan.

Not applicable

fabs(x)

The absolute value of x. The result is a positive number.

Examples:

fabs( 2.4 ) returns 2.4

fabs( -3.8 ) returns 3.8

*******************************************

or subtract greater-smaller

er_mohit
Master II
Master II

try this way

  Interval(timestamp_to - timestamp_from, 'hh:mm') as rest_time

Not applicable

Hi,

Please find the attached file. I hope it helps you

Thanks and Regards,

S. Amuthabharathi

qw_johan
Creator
Creator
Author

Thanks 🙂 it helped