Cognos
Cognos
Expression Result
cast(extract( year, [Time stamp]), varchar(4)) 2009 (alpha)
extract( hour, [Time stamp]) 17 (numeric)
extract( day, [Time stamp]) 8 (numeric)
cast(extract(month,[Time stamp]),VARCHAR(2)) 6 (alpha – note lack of leading zero)
cast([Time stamp], date) Jun 8, 2009 (‘date’ is a data type)
cast ([Time stamp], varchar(50)) 2009-06-08 00:00:00.000000000
cast(extract (hour,[Time stamp]), VARCHAR(2)) 5 (alpha)
_last_of_month(date2timestamp(Today()))
_add_days([Audit].[COGIPF_RUNREPORT].[TIME STAMP],-1)
8/4/2010 Page 1
Report Studio
or
SYSDATE
This CASE function extracts the first three characters of the current date and translates it
into a fiscal period:
CASE (substr({sysdate},4,3))
WHEN 'JUL' THEN '01'
WHEN 'AUG' THEN '02'
WHEN 'SEP' THEN '03'
WHEN 'OCT' THEN '04'
WHEN 'NOV' THEN '05'
WHEN 'DEC' THEN '06'
WHEN 'JAN' THEN '07'
WHEN 'FEB' THEN '08'
WHEN 'MAR' THEN '09'
WHEN 'APR' THEN '10'
WHEN 'MAY' THEN '11'
WHEN 'JUN' THEN '12'
ELSE '14'
END
To calculate the fiscal year based on the current date (fiscal year for 2009/2010 is 2010):
8/4/2010 Page 2
Report Studio
OTHER
TRUNC(date, [format])
Examples:
Start of today:
Code: trunc({sysdate})
8/4/2010 Page 3
Report Studio
8/4/2010 Page 4
Report Studio
'D'-- Return only day information in the timestamp. Hours, minutes, and seconds are
returned as zero.
'h'-- Return only day and hour information in the timestamp. Minutes and seconds are
returned as zero.
'm'-- Return only day, hour, and minute information in the timestamp. Seconds are
returned as zero.
's'-- Return only day, hour, and second information in the timestamp, but do not show
milliseconds.
TRUNC also can be used with decimal numbers to return a number rounded to a given number
of decimal places. For example:
8/4/2010 Page 5