Format Dates as Strings in Cognos: Patterns, Conversions and Tradeoffs
How Cognos date format patterns differ from converting a date to a string, what each changes, and how sorting, locale, export and readability are affected.
In IBM Cognos there are two separate ways to make a date look a certain way. You can keep the value as a date and change its display format, or you can turn it into text with an expression. Both can show the same characters on the page, but they behave differently once the report is sorted, filtered, exported, translated or read by assistive technology. This review explains the difference and when each approach suits the job.
Is converting a date to a string the right choice?
For most reports, formatting is the safer default. A data format pattern changes only how the date is presented, so the value still sorts, filters and aggregates as a date and can follow the report's locale. Converting a date to a string is worth it when the text itself is the goal. Examples are building a label that combines a date with other words, producing a fixed key such as 20260304, or feeding a downstream system that expects one exact text layout.
The main tradeoff is that a string is no longer a date. Once converted, the value sorts alphabetically, loses locale awareness, and may export as text rather than as a date. If readers or downstream tools need to sort, filter or calculate with the value, keep it as a date and format it. Convert it only at the last step where text is actually required.
What each approach actually changes
The word 'format' is used loosely for both techniques, so it helps to separate them.
- Data format (presentation only): the stored value stays a date or timestamp. The Data Format property controls how it is rendered, using a predefined style or a custom pattern.
- String conversion (value change): an expression such as cast or concatenation creates a new text value. Its characters are fixed when the expression is evaluated, and the original date type is gone for that data item.
A quick test tells you which one you have. If changing the report language changes the month name, or sorting the column still orders the dates chronologically, the item is a formatted date. If the text stays identical in every locale and sorts character by character, it is a string.
Cognos date format patterns
In the Data Format dialog, a date, time or date-time format can take a custom Pattern instead of a preset style such as short, medium or long. The pattern symbols follow the widely used convention in which letters stand for date parts. Check the symbol table in the documentation for your Cognos version, because support for less common symbols can vary. The examples below assume a date of March 4, 2026 at 14:05 rendered in an English locale.
| Pattern | Example output | Notes |
| yyyy-MM-dd | 2026-03-04 | Year-month-day order; sorts correctly even as text |
| MM/dd/yyyy | 03/04/2026 | Common US layout; ambiguous to readers who expect day first |
| MMM d, yyyy | Mar 4, 2026 | Abbreviated month name, follows the locale |
| MMMM d, yyyy | March 4, 2026 | Full month name, follows the locale |
| EEEE, MMMM d | Wednesday, March 4 | Full weekday name |
| HH:mm | 14:05 | 24-hour clock; mm is minutes |
| hh:mm a | 02:05 PM | 12-hour clock with AM/PM marker |
- Symbols are case sensitive. MM is month and mm is minutes, so a pattern written as yyyy-mm-dd shows minutes where the month should be.
- Repeating a letter changes its width or form. d gives 4, dd gives 04, MMM gives an abbreviated name and MMMM gives the full name.
- Literal words inside a pattern are normally wrapped in single quotes so they are not read as symbols.
- Month and weekday names come from the locale the report runs in, so the same pattern can produce different words for different users.
Converting a date to a string in an expression
When you need text, the most direct route is casting the date to a character type. The examples use a hypothetical data item called [Order Date].
cast([Order Date], varchar(10))
The text layout a plain cast produces can depend on the data source and query mode, so run it against your own package before relying on a particular order of year, month and day. If you need a guaranteed layout, build it from the date parts instead. One approach that uses only arithmetic and casting produces a compact year-month-day key:
cast(
extract(year, [Order Date]) * 10000
+ extract(month, [Order Date]) * 100
+ extract(day, [Order Date]),
varchar(8)
)
Adding the parts this way avoids any need for zero padding, because the result is always eight digits. For a separated layout such as MM/dd/yyyy, the month and day must be padded to two digits. One way to do that with common functions is to add 100, cast the result, and keep the last two characters:
substring(cast(100 + extract(month, [Order Date]), varchar(3)), 2, 2)
|| '/' ||
substring(cast(100 + extract(day, [Order Date]), varchar(3)), 2, 2)
|| '/' ||
cast(extract(year, [Order Date]), varchar(4))
Some data sources return extracted parts as decimals. In that case the cast may include a decimal point or trailing zeros, and the padded pieces will be wrong. Test the expression on real data, and wrap the extracted values in an integer cast if needed. Database-specific functions, such as a vendor's own date-to-character function, can be shorter. However, they tie the report to that database and may not work across packages.
Will the result stay readable and usable after sharing?
- Sorting: a string sorts character by character. Text in MM/dd/yyyy form groups dates by month across years, while yyyy-MM-dd and yyyyMMdd keep chronological order. A formatted date sorts correctly whatever pattern it displays.
- Filtering and prompts: filter on the underlying date rather than the converted text. Comparing strings for date ranges is error-prone, and a filter on a computed string may not be passed to the database as efficiently as a filter on a date column.
- Locale: a string is frozen in one language and layout. If the report serves readers in several locales, a data format pattern or preset style adapts to each of them, but a cast string does not.
- Export and copy: a converted string will reach spreadsheets and CSV files as text, so recipients cannot sort or calculate with it as a date without re-parsing. How a formatted date item is exported depends on the output format and Cognos version, so check an actual export before promising recipients a true date column.
- Readability and assistive technology: purely numeric dates such as 03/04/2026 are ambiguous to readers who expect day-first order. Spelling out the month, as in March 4, 2026, removes that ambiguity for people and for screen-reader listeners. This review has not tested how any specific screen reader announces Cognos report output.
When to keep the plain date value
Keep the value as a date and apply only a display format when the column will be sorted, filtered, used in calculations, exported for further analysis, or shown to readers in more than one locale. Use a string when the date is only one part of a larger text label, when a fixed machine-readable key is required, or when a receiving system demands one exact layout. If you do convert, a year-month-day order such as yyyy-MM-dd is the least ambiguous choice and still sorts correctly as text. Keeping the original date item available in the query alongside the string lets you sort and filter on the real value.
Gaps in this review
No version-specific test results were available. The exact output of a plain cast, the export behavior of formatted dates, and the full list of supported pattern symbols are therefore described as things to verify rather than as confirmed behavior. Results can differ by Cognos version, query mode, data source and output format. Run a short check with your own package, locale settings and export target before standardizing on one approach.