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

Announcements
Register by January 31 for $300 off your Qlik Connect pass: Register Now!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

time difference in qlikview

how to calulate time difference

6 Replies
swuehl
Champion III
Champion III

sarathi87k,

is your question answered (because you set the status alike, but you posted and set the status to assumed at the same time, so I assume this was done by mistake)?

If not:

It's easy to calculate a time difference in qlikview.

1) take care that the two timestamps you want to calculate the time difference from are QV timestamps with a numeric representation (integer part represents days, decimals the fraction of a day). If needed, use timestamp#() function to interpret a string as a timestamp.

2) Just subtract your two timestamps:

=TIMESTAMP2 - TIMESTAMP1

3) Format the result as needed using interval() function, e.g.

=interval( TIMESTAMP2 - TIMESTAMP1, 'hh:mm')

[check format codes in the HELP for more details]

Hope this helps,

Stefan

tappij2012
Contributor II
Contributor II

Hi,

What should I do when the timestamp 1 is newer then the timerstamp 2 in a tabel?

This because both ways are possible in a tabel.

Example:

timestamp 2           -  timestamp 1

10-03-2013 17:00 - 10-03-2013 08:00      result: 09:00 (h:mm)

10-03-2013 17:00 - 10-03-2013 18:00      result: -01:00 (h:mm)

What kind of expression I need to make this possible?

Not applicable
Author

In these cases you better use conditional statement and do the substraction.

Not applicable
Author

Hi,

You can try this

If(TIMESTAMP2> TIMESTAMP1,interval( TIMESTAMP2 - TIMESTAMP1, 'hh:mm'),interval(TIMESTAMP1-TIMESTAMP2, 'hh:mm'))

Hope this help.........

tappij2012
Contributor II
Contributor II

Thanks, this works good for me.

Only the I'll don't get a negative value, but that doesn't matter me.

Not applicable
Author

You can use the fabs function to turn that negative value positive.