COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: gatorfe on 20 Jul 2011 03:29:23 PM

Title: How to make date field show year month only
Post by: gatorfe on 20 Jul 2011 03:29:23 PM
I have a date field that I want to change to only show the year and month.  The date currently shows as 2011-07-20.  I want it to show 2011-07.  I also want to be able to group this new calculation so all the lines in the report for 2011-07 are together. How can this be done?  thanks in advance for your suggestions!
Title: Re: How to make date field show year month only
Post by: Arsenal on 20 Jul 2011 04:07:55 PM
I think extract(monthyear, date_queryitem) might help you out to extract the just the year and month and then just group on the list column that is being fed by this newly extracted data item
Title: Re: How to make date field show year month only
Post by: ksr on 21 Jul 2011 06:18:28 AM
Just Rt click on the field,
select style,
select "Data format"
select Format Type as Date
Select YES for the "Display Years" property
Select YES for the "Display Months" Proerty


Title: Re: How to make date field show year month only
Post by: gatorfe on 21 Jul 2011 12:34:41 PM
neither worked :(
Title: Re: How to make date field show year month only
Post by: Lynn on 22 Jul 2011 07:17:27 AM
If you want to group on it then I don't think you can use the data format properties since those will just change how the value is displayed.

Extract returns integer values so you'd need to convert them back to strings to paste them together in the format you want (then you'd also need to do something for preceding zero for months with only one digit).

If you are using Oracle the TO_CHAR function is ideal for this sort of thing. Or you can try the cast function to convert to a string and then substring it:

substring( cast ( [Namespace].[QuerySubject].[Date Field], VARCHAR(10) ), 1, 7 )
Title: Re: How to make date field show year month only
Post by: Mpotla on 29 Jul 2011 07:16:12 AM
Hi ,

we can set this using Pattern property in the data format.

Select the data item->Data formar(in the properties)->Select type as Date-> down in the properties list  we have something called Pattern. Just put your pattern YYYY-MM. Set Yes to Display Years, Yes to Display months.

Hope this would help!