COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: sgoode on 03 Jan 2011 11:32:10 AM

Title: adding hours and minutes to a timestamp
Post by: sgoode on 03 Jan 2011 11:32:10 AM
I am trying to add hours and minutes to a timestamp.  Over the last week I have found many suggestions via the web but none that would work for this scenario.  What I have is a timestamp and then a variable with hours and another variable with minutes I want to subtract from the timestamp.

Things I have tried:
_add_days([call_stop_ts], [hours_minus]/24)
The above does not work due to the second argument requires an integer value it appears. 
So for example:
[hours_minus] = 4
_add_days([call_stop_ts], 4/24)
evaluates to:
_add_days([call_stop_ts], 0.167)
Then when the second parameter has to be an integer you get:
_add_days([call_stop_ts], 0) 
So nothing is changed.

I have also tried:
[call_stop_ts] - [hours_minus] hour
This does not work as it does not allow the value before hour to be a variable.
This works : [call_stop_ts] - 3 hour but I need the 3 value to be variable.





Title: Re: adding hours and minutes to a timestamp
Post by: kramben on 11 Feb 2011 10:21:54 AM
Have you figured out a solution to this issue?  I am having the same problem myself.  I need today's date but make it 7AM.

Thanks,

~Mark
Title: Re: adding hours and minutes to a timestamp
Post by: Lynn on 11 Feb 2011 10:38:43 AM
Maybe go after it from a different angle. Instead of trying to add or subtract time, just build a string that has what you want and then cast the whole mess into a timestamp.

If all you need is the current date at 7:00 am this works:

cast ( cast( current_date, VARCHAR(15) ) || ' 07:00:00' , TIMESTAMP )
Title: Re: adding hours and minutes to a timestamp
Post by: kramben on 19 Jan 2012 08:58:40 AM
Thanks for your response.

This is what I did for my solution.  Using Oracle DB.

TRUNC({SYSDATE}) + 7/24

Hope this helps.