COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: aji136 on 04 Feb 2008 12:56:05 AM

Title: Getting Monthname from a date field
Post by: aji136 on 04 Feb 2008 12:56:05 AM
Hi,

How do I get monthname from a datefield - I have tried the function monthname(fieldname) but it comes up with an error. I am using Report Studio v8.2. The source database is Access. Appreciate if anyone can help me on this...

Error Message:
RQP-DEF-0177

       An error occurred while performing operation 'sqlPrepareWithOptions' status='-69'.


Cheers,
Aji
Title: Re: Getting Monthname from a date field
Post by: Suraj on 04 Feb 2008 09:24:17 AM
First of all, create a data item that extracts month using extract (month, [Date Field]). This will give you 1, 2 3, ... depending on Jan, Feb, Mar, ...
Then, create a case statement such as
case
when [data item] = 1 then 'January'
when [data item] = 2 then 'February'
.
.
.
when [data item] = 11 then 'November'
else 'December'
end

This will replace the extracted month to month names.
Title: Re: Getting Monthname from a date field
Post by: aji136 on 04 Feb 2008 04:17:43 PM
Thanks Suraj but this is what I had done as a workaround. I thought there would be an easy way out by just specifying monthname(date field). This works fine directly from MS Access query. Though Cognos includes this function as part of the Access function list, it doesn't seem to work. Have you got this function to work directly from Cognos?
Title: Re: Getting Monthname from a date field
Post by: Suraj on 05 Feb 2008 09:31:28 AM
We have month indicator in our date field that we can compare numbers with to get month name. So we don't have to write that case statement.
Title: Re: Getting Monthname from a date field
Post by: Modtamod on 05 Feb 2008 03:05:38 PM
to get month type in this expression
extract(month,date expression)
Title: Re: Getting Monthname from a date field
Post by: MFGF on 28 Mar 2008 05:28:15 AM
If you just want to show the month name from your date field, use the Format property of the date value and you can take control of which parts of the date are displayed and how they are displayed.

Regards,

MF.