Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Read about Qlik’s Response to COVID-19 Read the Letter, Join the Group.
Not applicable

Convert a duration into a number of hours

Hello everyone,

I have a metric which provides me a duration in the following format : HH:SS

I would like to obtain a numeric value indicating the exact number of hours for this duration.
for example if the duration is 03:30 (3h30min) I want to obtain 3.5 as a number.

Is there any function that could help me with that ?

Thanks you very much

Alexandre BERNARD

Tags (3)
1 Solution

Accepted Solutions
Highlighted
MVP
MVP

Re: Convert a duration into a number of hours

Multiply by 24 rather than divde:

     Interval#('3:30', 'H:mm') * 24 = 3.5

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

6 Replies
Highlighted
Honored Contributor II

Re: Convert a duration into a number of hours

If the duration is a timestamp, you can divide by 24.

Highlighted
Partner
Partner

Re: Convert a duration into a number of hours

try this and use your timefield instead of "03:30"

=num(left('03:30',2) & ',' & Right('03:30',2)/6)

Highlighted
Not applicable

Re: Convert a duration into a number of hours

The problem is that I want to convert a duration into a number. The format is different so I cant Divide it.
Are there any functions that convert Time duration into numbers ?

Highlighted
MVP
MVP

Re: Convert a duration into a number of hours

Multiply by 24 rather than divde:

     Interval#('3:30', 'H:mm') * 24 = 3.5

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

Highlighted
MVP
MVP

Re: Convert a duration into a number of hours

If the time duration is calculated using QV time values and functions, it is actually a number, representing days. Shorter intervals will be fractions of a day; 1 hour has a value of 1/24. So if you multiply the interval by 24 you will get a value in decimal hours.

If the interval is a string value, then you can convert that to a QV numeric interval using Interval# (as I did above).

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Highlighted
Honored Contributor

Re: Convert a duration into a number of hours

Hi Alexandre,

Please try:

Convert time stamp into hour decimal value :

hour( interval(([timestamp]/86400), 'hh:mm:ss') )

           + (((Minute (interval(([timestamp]/86400), 'hh:mm:ss')) * 100) / 60)

           + (Second (interval(([timestamp]/86400), 'hh:mm:ss')) * 100) / 3600 ) / 100

or

If the field is TimeSecond then you can convert using below:

(TimeSecond /3600)  which converts Seconds to duration in decimal

Regards

Neetha