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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
lukaspuschner
Partner - Creator
Partner - Creator

Negative time

Hello,

I have a filed with positive and negative secconds.

i want to have it in a time format. thats no problem for the positive values, but hot to make -120 secconds to - 00:02:00 ?

time(Floor((ABW) / 3600) & ':' &  Floor(mod((ABW), 3600)/60) & ':' & mod((ABW) , 60),'hh:mm:ss')

this is the code i have

1 Solution

Accepted Solutions
ashfaq_haseeb
Champion III
Champion III

Hi,

Try below in load script.

Load *,if((Time)<0,'-'&interval(timestamp#(fabs(Time), 's'), 'hh:mm:ss'),interval(timestamp#(fabs(Time), 's'), 'hh:mm:ss')) as Test;

Load * Inline

[

Time

-120

120

];

Regards

ASHFAQ

View solution in original post

9 Replies
Anonymous
Not applicable

= time ( fabs ( (-120) ) / 24 / 60 / 60   ,'hh:mm:ss')

You can replace the -120 with your field ABW.

lukaspuschner
Partner - Creator
Partner - Creator
Author

i ll try it, thank you

lukaspuschner
Partner - Creator
Partner - Creator
Author

this returns 00:02:00.

but i want to have - 00:02:00

ashfaq_haseeb
Champion III
Champion III

Hi,

Try below

=interval(timestamp#(fabs(-120), 's'), 'hh:mm:ss')

Replace -120 with your field

Regards

ASHFAQ

whiteline
Master II
Master II

Hi.

Use Interval function instead of time. Time can't be negative.

ashfaq_haseeb
Champion III
Champion III

Hi,

Try below in load script.

Load *,if((Time)<0,'-'&interval(timestamp#(fabs(Time), 's'), 'hh:mm:ss'),interval(timestamp#(fabs(Time), 's'), 'hh:mm:ss')) as Test;

Load * Inline

[

Time

-120

120

];

Regards

ASHFAQ

Not applicable

Hei ~

I don't know if you need the exact Time object or just the representation,

how about something like this for the representation

=If (TimeField< 0, '-', '') & Maketime(Floor(TimeField/3600), Floor(mod((TimeField), 3600)/60), Mod((120) , 60))

that would yield -12:02:00 am...

just add the desired format to the MakeTime function using Time, or Interval like this (this one gives exactly the one from your example, except the negative Time object)

=If(-120 < 0, '-', '') & Interval(Maketime(Floor(fabs(-120)/3600), Floor(mod((fabs(-120)), 3600)/60), Mod((fabs(-120)) , 60)), 'hh:mm:ss')

where -120 is your original example (ABW)

I don't really know if QlikView supports "Negative time values" per se, but this is a workaround you visualization anyways,

hope it helps, c ya

Not applicable

Load *,if((Time)<0,'-', '') & Interval(timestamp#(fabs(Time), 's'), 'hh:mm:ss') as Test; // code compression FTW, ;D

omerfaruk
Creator
Creator

Appreciate this is an old thread but currently, QlikView supports -hh:mm format. You don't need to append a minus sign.