COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Framework Manager => Topic started by: donlkj on 15 Feb 2013 07:57:22 AM

Title: how can I subtract a number from datetime
Post by: donlkj on 15 Feb 2013 07:57:22 AM
I have got two columns in DB2:

name:time_st   type: timestamp
name:duration   type: integer (means secundum)

example:
time_st: 2013-02-15 18:10:00 0000
duration: 300

task:
time_st-duration:
2013-02-15 18:10:00  - 300 sec, expected result: 2013-02-15 18:05:00


I tried but not working (in framework manager)
->   timestampadd(2, duration, time_st)
->   time_st - duration second (like currenttime - 3 second)

How can I solve it?

any idea?
donlkj
Title: Re: how can I subtract a number from datetime
Post by: bi4u2 on 15 Feb 2013 10:07:21 AM
I am not sure what studio you are working in but there is an easy solution in Report Studio. Add a new data item to your query, go to the Functions tabs, then the Constants folder and grab an item called 'interval minute'. It inserts a '0 minute' but you can change this and the add or subtract this item to your timestamp item. I am attaching my results. I changed the interval to say '5 minute'.
Title: Re: how can I subtract a number from datetime
Post by: donlkj on 16 Feb 2013 10:28:12 AM
OK, but I would like to use 2 columns.( instead of constant.)
I have got a timestamp column, and from this timestamp column I would like to subtract an other column (which is integer).

And if it possible in the model.
Title: Re: how can I subtract a number from datetime
Post by: blom0344 on 18 Feb 2013 02:57:17 AM
You could write an SQL query subject using DB2 syntax that allows using the seconds,microseconds etc definitions:

Select sometable.sometimestamp-(othertable.value)/1000 microseconds from ......................