COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: newyork66 on 29 Jul 2008 09:04:21 AM

Title: Convert a number to a time format
Post by: newyork66 on 29 Jul 2008 09:04:21 AM
Database column is a number ( It's actually a total milliseconds)
To be meaningful to the business, we need to display this as hh:mm:ss  (hh - hours, mm - minutes, ss - seconds). Ms / 1000 = Seconds. Seconds / 60 = Minutes (integer) + Seconds (remainder). Minutes / 60 = Hours (integer) + Minutes (remainder). No decimal places. So, 2,022,523 = 33:42 (no hours).
How can I achieve these in Cognos Report Studio?
Title: Re: Convert a number to a time format
Post by: m23 on 31 Jul 2008 12:12:09 AM
I would do it like this..

trunc(2022523/3600000)||':'||trunc(mod(2022523,3600000)/60000)||':'||trunc(mod(mod(2022523,3600000),60000)/1000)

trunc is an oracle function that just gets rid of the decimals. If your database isn't oracle using whatever your database has to round down to the nearest whole number would do the same thing. Someone may correct me but I don't think Cognos has any inbuilt function for rounding down.