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

Announcements
Only at Qlik Connect! Guest keynote Jesse Cole shares his secrets for daring to be different. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
vlad_komarov
Partner - Specialist III
Partner - Specialist III

Converting Seconds to hh:mm:ss format without using Interval() function

Hello,

I have a data set where some time values are presented in seconds. Data on the chart should be displayed in hh:mm:ss format.

I've used the Interval() function in the script:

     Interval(time_field/86400, 'hh:mm:ss') as TIME_VALUE

and everything was looking good.

But,

I need to avoid any data transformation in my script and simply rely on data from the database.

I was hoping that using the same approach on the data side (code from the View Script):

     CAST (TIME_SEC / 84600 AS NUMBER (20, 18)) AS TIME_FULL

will work the same way, but I've noticed some rounding (?) issues.

With small values in seconds, everything looks good:

time_1.jpg

With values growing, the error increases:

time_2.jpg

And the difference reaches significant values when time in seconds represent large interval (more than 2 minutes difference in ~1,5 hours range....):

time_3.jpg

I could not find any reasonable explanation for that.

I would appreciate any suggestions.

Regards,

Vladimir

6 Replies
tresesco
MVP
MVP

danieloberbilli
Specialist II
Specialist II

http://qlikviewcookbook.com/2011/10/correct-time-arithmetic/

I agree with tresesco - this is the right source. Especially have a look at Robs comment: avoid using division to convert time.

See also the link above

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

You want to avoid transforming the data in QV - that's fine. Interval() does not transform the data, it simply formats to hh:mm:ss (or other format that you specify) - the underlying data value is unchanged.

You can prove this to yourself by entering something like this in a text box:

     =Num(Interval(3233))

Num gets the underlying value...

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
vlad_komarov
Partner - Specialist III
Partner - Specialist III
Author

Jonathan,

Regardless the transformation definition:

Why TIME_1 and TIME_2 are significantly different?

Interval(TIME_SECONDS/86400, 'hh:mm:ss') as TIME_1,  
Interval(TIME_DIV_BY_86400, 'hh:mm:ss') as TIME_2,

Somehow QV know how to round the value correctly??

vlad_komarov
Partner - Specialist III
Partner - Specialist III
Author

It's good article and nice discussion , but it's still not clear for me why QV's Interval() function works better in this case...

Interval(TIME_SECONDS/86400, 'hh:mm:ss') as TIME_1,   // result is correct 

Interval(TIME_DIV_BY_86400, 'hh:mm:ss') as TIME_2,       // result is wrong

Somehow QV know how to round the value correctly??

vlad_komarov
Partner - Specialist III
Partner - Specialist III
Author

Excel works perfectly too...

SECONDSSECONDS/86400EXCEL FORMATTED
58650.0678819444444444001:37:45