Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
richnorris
Creator II
Creator II

Find the difference in hours between two timestamps?

Hi, I'm trying to find the difference of two timestamps using interval(a-b), only I don't fully understand the numbers involved. Could anyone help explain to me how timestamp works? Essentially I want to say,

vAge = interval(timestamp(now()) - B)

if vAge <= '8 hours' Then

do something

The touble I'm having is working out what '8 hours' should look like? I've not had much luck deciphering the number that a timestamp gets converted from / to, from what I gather 0.0007 = 1 minute? Any help would be much appreciated! Thanks.

1 Solution

Accepted Solutions
Not applicable

The number that date arithmetic returns is in 'Days'. To convert days to hours, you divide multiply by 24.

To convert 8 hours into the number of days, for comparison purposes:

1 day / 24 hours = 0.0416 X 8 hours = 0.33 (repeating)

The same holds for minutes, seconds, years, etc. Just treat whole numbers as 'days', and convert.

So in your case, I would take the time that I want to compare (8 hours) and convert that using the formula, and then just compare that to your date calculation.

View solution in original post

5 Replies
richnorris
Creator II
Creator II
Author

So, 8 hours seems to equate to 0.33334, but I only found that through trial and error and am still really non the wiser as to why I'm using this value. There must be a more straightforward way of checking the difference in hours between two times?

Miguel_Angel_Baeyens

Hello Rich,

That value is equivalent to say that 8 hours are a third of a day. Interval() is used when the resulting time is more than 24 hours, and want to be showed as hours:mins:secs. So I'm guessing you are looking something like (untested)

=interval(time('12:30', 'hh:mm') - time('03:54', 'hh:mm'), 'hh:mm')


will return something like '08:36'.

Hope that helps

Not applicable

The number that date arithmetic returns is in 'Days'. To convert days to hours, you divide multiply by 24.

To convert 8 hours into the number of days, for comparison purposes:

1 day / 24 hours = 0.0416 X 8 hours = 0.33 (repeating)

The same holds for minutes, seconds, years, etc. Just treat whole numbers as 'days', and convert.

So in your case, I would take the time that I want to compare (8 hours) and convert that using the formula, and then just compare that to your date calculation.

neetu_singh
Partner - Creator III
Partner - Creator III

Hi Ryan,

I have done this that how to calculate the difference between hours in two timestamps.

I m sending you the attachment. Please upload the test file and check it out. is this the what you required or not.

I have selected two date with timestamp and now, it will take starting hour and ending hour and calculate the difference between them.

I think this is something like that what you required.

Plz let me know its fruitful for u or not.

Thanks

Neetu Singh

sumitjadhav
Creator II
Creator II

Hi neetu,

Can you please send the logic ,because of personal edition ,I cant open your Qlikview app.

Thank's & Regards,

Sumit Jadhav.