Formatting date-and-time data
You can display date-and-time data in different formats. You can, for example, display dates and times in short, medium, or long formats. By default, reports display date-and-time data according to the locale configured on the user’s machine. For example, a short date that appears as 5/7/09 in the English (United States) locale appears as 07.05.09 in the German (Germany) locale. If you want some dates to always appear in a specific locale’s format, set the locale for that data element.
Display date-and-time data using either a text element or a data element, depending on what you want to accomplish. When you drag a data set field from Data Explorer and drop it on the report page in the layout editor, BIRT Report Designer creates a data element to display the values of the data set field. The procedure for formatting data differs for a data element and a text element, and is described in the following sections.
Formatting date-and-time data in a data element
Specify the format for date-and-time data in a data element by setting the element’s Format DateTime property. As Figure 8‑4 shows, BIRT Report Designer provides many common date-and-time formats from which to choose. Optionally, choose a locale. Use the locale’s Auto value to display the data according to the locale set on the user’s machine.
Figure 8‑4 Format DateTime property values
You can also define your own date-and-time formats. For example, you can specify two-digit months, use two digits for the year, or add the day of the week. To define a custom format, use special symbols to construct a format pattern. BIRT Report Designer supports the Java formatting defined by the SimpleDateFormat class. For details about the supported formatting symbols, see the Javadoc for SimpleDateFormat.
Table 8‑3 shows examples of custom format patterns and their effects on a date that is stored as 4/15/2009 in the data source.
Table 8‑3 Results of custom date format patterns
Format pattern
E, M/d/yyyy
Wed, 4/15/2009
EEEE, M/dd/yy
Wednesday, 4/15/09
Apr 15
3 (the week in the month)
16 (the week in the year)
105 (the day in the year)
Specify custom formats if a report will be viewed in only one locale because custom formats always display date or time data in the specified format. For example, if you use the format MM‑dd‑yy, the date January 10, 2006, always appears as 01‑10‑06, regardless of the locale in which the report is viewed. For locales in which dates are displayed in day‑month‑year format, a 01‑10‑06 date is interpreted as October 1, 2006.
Formatting date-and-time data in a text element
To insert dynamic data in a text element, use the VALUE-OF tag. To format the dynamic data, include a format attribute that specifies the format, as shown in the following examples:
<VALUE-OF format="MM-dd-yyyy">row["orderDate"]</VALUE-OF>
<VALUE-OF format="M/d/yy hh:mm:ss">new Date()</VALUE-OF>
You can use any format pattern that the Format DateTime property supports, as described in the preceding section.