COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: Raghuvir on 10 Dec 2014 03:15:53 AM

Title: Date format issue
Post by: Raghuvir on 10 Dec 2014 03:15:53 AM
Hi all,

i have a data item with the following condition written in it.

cast(Day([Empl_Payroll].[VALUE_DATE]),varchar(2))||'-'||
CASE
WHEN  Month([Empl_Payroll].[VALUE_DATE])=1  THEN ('Jan')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=2  THEN ('Feb')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=3  THEN ('Mar')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=4  THEN ('Apr')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=5  THEN ('May')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=6  THEN ('Jun')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=7  THEN ('Jul')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=8  THEN ('Aug')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=9  THEN ('Sep')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=10  THEN ('Oct')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=11  THEN ('Nov')
WHEN  Month([Empl_Payroll].[VALUE_DATE])=12 THEN ('Dec')
ELSE  ('None')
END
||'-'||
substring(cast(year([Empl_Payroll].[VALUE_DATE]),varchar(4)),3,2)

when place the data item on the layout and run the report the date what i get is "4-Dec-14" whereas i want it to be "04-Dec-14"

Request you to guide me to achieve this.

Regards
Title: Re: Date format issue
Post by: RandomHunter on 10 Dec 2014 07:25:43 AM
Hi,

try replacing the first part by this:

if ( Day([Empl_Payroll].[VALUE_DATE])  < 10 )
then ('0')
else ('') || '-' || cast(Day([Empl_Payroll].[VALUE_DATE]),varchar(2))

Regards,
Hunter

Title: Re: Date format issue
Post by: bdbits on 10 Dec 2014 10:09:22 AM
If VALUE_DATE is a real date datatype, as it appears to be in your expression, you are working way too hard. Just drop the column on your report, right-click and choose Style > Data format, pick Date from the Format type dropdown. Scroll down the options on the right and enter dd-MMM-yy in Pattern.