COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: SarahCL on 13 Aug 2015 04:12:36 PM

Title: Convert hours into DD:HH:MM format
Post by: SarahCL on 13 Aug 2015 04:12:36 PM
Hi all!

New day new challenge. I have a column in my report that is in hours. Client wants to see in x days, x hours, x minutes

I used this link to http://www-01.ibm.com/support/docview.wss?uid=swg21339322 (http://www-01.ibm.com/support/docview.wss?uid=swg21339322) to help so my data items are as follows:

[Days] : cast((floor([myField]/24)), varchar(10))
[Hours] : cast(floor(([myField]-(floor([myField]/24))*24)), varchar(10))
[Minutes] : cast(([myField]-(floor([myField]/60)*60)), varchar(10))

but I am realizing that it is not pulling a correct result. # days look right, # hours are right but # minutes are off (left the decimals on purpose). It looks like the minutes are just mirroring one number before the decimal point and the decimals. Doesn't look like it is calculating anything.

Anyone as a simpler solution or can tell me whats is wrong with the minutes calculation?
Title: Re: Convert hours into DD:HH:MM format
Post by: BigChris on 14 Aug 2015 02:16:52 AM
couldn't you do the minutes calculation as ([myField] - ([Days] *24) - [Hours]) * 60 ?
Title: Re: Convert hours into DD:HH:MM format
Post by: SarahCL on 14 Aug 2015 08:32:31 AM
That worked!

Thank you so much! Although now I cannot get rid of the decimals with "floor"
Title: Re: Convert hours into DD:HH:MM format
Post by: BigChris on 14 Aug 2015 08:48:54 AM
what happens if you try doing the calculation without the cast? What do you get from the following:

Days: floor([myField]/24)
Hours: floor([myField]-floor([myField]/24)*24)   or
Hours: floor([myField] - [Days] * 24)
Mintues: ([myField] - ([Days] *24) - [Hours]) * 60
Title: Re: Convert hours into DD:HH:MM format
Post by: SarahCL on 14 Aug 2015 09:17:41 AM
Looks good too but my minutes still have lots of decimals I would like to trim

ETA: forgot my _round...

all good thanks!