COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: kaevne on 30 Jan 2009 05:54:28 PM

Title: Add/Subtract minutes/hours from dateTime?
Post by: kaevne on 30 Jan 2009 05:54:28 PM
We are trying to subtract minutes and hours from a user-selected datetime and seem to have run into a roadblock.  Cognos has _add_days, _add_months, and _add_years functions, but no _add_minutes or _add_hours functions!  Anyone know how to do so?  Thanks!
Title: Re: Add/Subtract minutes/hours from dateTime?
Post by: John_Russell on 03 Feb 2009 02:52:26 PM
You have to get pretty creative with this one!  The following formula seems to have worked well for me.  Just substitute your date/time fields for my dummy start/end times and you should be golden.

mod((24+(to_number(to_char([END_TIME];'SSSSS') - to_char([START_TIME];'SSSSS')) /3600)),24)
Title: Re: Add/Subtract minutes/hours from dateTime?
Post by: kaevne on 03 Feb 2009 03:18:47 PM
Thanks John.  We're trying it out right now. Much appreciated.