Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
jcharles
Contributor III
Contributor III

Format a number to time


Good day

Please can you help me format a number to a time?

Numbers

600

612

700

730

1805

The times for the above should be:

06:00

06:12

07:00

07:30

18:05

I've tried using Time#(Number,'HH:MM') and Time(Number,'HH:MM') but both do not seem to work.

Please help - Thank you

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try like:

If(Len(Numbers)=3,Time(Time#(Numbers,'hmm') ,'hh:mm'), Time(Time#(Numbers,'hhmm') ,'hh:mm') ) as NewTime

View solution in original post

10 Replies
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

It should be

Time(Time#(Number,'Hmm'), 'HH:mm')

Hope it helps

tresesco
MVP
MVP

Try like:

If(Len(Numbers)=3,Time(Time#(Numbers,'hmm') ,'hh:mm'), Time(Time#(Numbers,'hhmm') ,'hh:mm') ) as NewTime

ashfaq_haseeb
Champion III
Champion III

Hi try below

=time(time#(Numbers,'hmm'),'h:mm')

Regards

ASHFAQ

jcharles
Contributor III
Contributor III
Author

Great!!! - Thank you Thank you

tresesco
MVP
MVP

Does it work for 4-digit number ?

Not applicable

Try this:

LOAD *,

Time#(Mid(Number,1,2)  & ':' & Mid(Number,3,2),'HH:mm') as FormatedTime;

LOAD if(len(Number)=3,'0'&Number,Number) as Number;

LOAD * INLINE [

    Number

    600

    612

    700

    730

    1805

];

jcharles
Contributor III
Contributor III
Author

Wonderful - this takes into account the change in the length of the number too - Thank you

CELAMBARASAN
Partner - Champion
Partner - Champion

No I missed that. But you can implement like below, instead of going for If condition

Time(Time#(Num(Number, '0000'), 'HHmm'), 'HH:mm')

anbu1984
Master III
Master III

Or like this

Time(Time#(Left('0'&Number,4),'HHmm'), 'HH:mm')