Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Difference in Time only (No Timestamp)

Need to calculate the time difference between two time considering the AM and PM factor.

My time are in this format

Start = 11:55:37 PM

End  = 1:10:33 AM

I know I have to use Interval() but I am getting only negative values as the AM PM is not being considered. I also need to display the total difference in minutes.

1 Solution

Accepted Solutions
MarcoWedel

Hi,

the best way would be to subtract timestamps instead of time values (including the date part as already suggested).

If this information is not available, then you can imply that the difference has to be positive and less than 1 (day).

So one possible solution could be:

QlikCommunity_Thread_145512_Pic1.JPG

=Interval(fmod(End-Start+1,1))

given your time values are already loaded as dual values (i.e. numerical formatted as time) like your screenshot suggests.

If your time fields are simply text, then you have to convert them (again as already suggested) like:

=Interval(fmod(Time#(End,'hh:mm:ss TT')-Time#(Start,'hh:mm:ss TT')+1,1))

hope this helps

regards

Marco

View solution in original post

8 Replies
Anonymous
Not applicable
Author

= interval ( time# ( '11:55:37 PM' , 'h:mm:ss tt' ) - time# ( '1:10:33 AM'  , 'h:mm:ss tt' ) , 'hh:mm:ss' )

maxgro
MVP
MVP

in minutes

(time#('11:55:37 PM', 'hh:mm:ss tt') - time#('1:10:33 AM', 'hh:mm:ss tt')) * 24*60

or

interval(time#('11:55:37 PM', 'hh:mm:ss tt') - time#('1:10:33 AM', 'hh:mm:ss tt'), 'mm')

Not applicable
Author

Thank you for the reply Bill but i'm still not getting the right results. Hope the below snap helps clarify my predicament:

Capture.PNG

On the first one the answer difference should have been 00:14:04 which is not the case

Anonymous
Not applicable
Author

Try subtracting the Start time from the End time.  Looks like you maybe doing it the other way round.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Add a date part to the underlying time value and your problem will be solved.

QlikView will consider 12:10:33 AM to be the morning of the same day, because the date value = 0. In your case, you would like to have this date part to be at least = 1...

Peter

MarcoWedel

Hi,

the best way would be to subtract timestamps instead of time values (including the date part as already suggested).

If this information is not available, then you can imply that the difference has to be positive and less than 1 (day).

So one possible solution could be:

QlikCommunity_Thread_145512_Pic1.JPG

=Interval(fmod(End-Start+1,1))

given your time values are already loaded as dual values (i.e. numerical formatted as time) like your screenshot suggests.

If your time fields are simply text, then you have to convert them (again as already suggested) like:

=Interval(fmod(Time#(End,'hh:mm:ss TT')-Time#(Start,'hh:mm:ss TT')+1,1))

hope this helps

regards

Marco

Not applicable
Author

Marco that is exactly what I needed. Thank you so much.

MarcoWedel

you're welcome

regards

Marco