Search code examples
db2cognoscognos-10

Add Filter to extract rows where the timestamp falls in between yesterday at 4 AM and today at 3 AM in Cognos


I am new to Cognos and I am trying to add a filter to a column that only allows rows that are in between Yesterday at 4 AM and today at 3 AM. I have a working query in db2 but when I try to add it to the filter in Cognos I get a parsing error. Also, I found in the properties that the data type for the column I am trying to filter to be Unknown (Unsupported) type. I started off by creating two Data Item Expressions for each time frame I am trying to limit the data by. But I got a parsing error on the first one:

[Presentation Layer].[Cr dtime]=timestamp(current date) - 1 day + 4 hour

This works in my db2 local test database but doesn't even compile in Cognos. I also tried casting the column into a timestamp but that isn't working either. Any help is appreciated. I also tried using the _add_days function but I still get a parsing error. Also sampling the column I get values that appear to be timestamps as this string: 2016-01-02T11:11:45.000000000

Eventually if I get the two filters working I expect the original filter to be close to this syntax:

[Presentation Layer].[Cr dtime] is between [Yesterday 4AM] AND [Today 3AM]


Solution

  • Here is your filter:

    [Presentation Layer].[Cr dtime] between
    cast(_add_hours(_add_days(current_date,-1),4),timestamp) 
    and 
    cast(_add_hours(current_date,3),timestamp)
    

    This works because current_date in Cognos does not have a time component. If you were to cast it directly to a timestamp type you would see the time part of the date as 12:00:00.000 AM, or midnight. Knowing this we can then simply add how much time after midnight we want, cast as a timestamp type and use this in the filter.