Working with custom formats
Report Studio also enables you to specify a custom format for numeric, date‑and‑time and string data, in cases when the available standard formats do not meet your requirements. To apply a custom format to data, you specify a format pattern.
Applying a custom number format
You can define a custom number format using special symbols to construct a format pattern. A format pattern shows places held by the currency symbol and the thousands and decimal separators. The thousands separator and the decimal separator are locale‑dependent. In the English (United States) locale, for example, a comma separates thousands places, and a period separates decimal places. In most European locales, a space separates thousands places, and a comma separates decimal places. Table 7‑3 lists example results of custom number format patterns.
Table 7‑3 Results of custom number formats
Format pattern
Data in original format
Result of formatting
0000.00
12.5
124.5
1240.553
0012.50
0124.50
1240.55
#.000
100
100.25
100.2567
100.000
100.250
100.257
$#,###
2000.00
20000.00
$2,000
$20,000
ID #
15
ID 15
Applying a custom date-and-time format
You can define a custom date‑and‑time format using special symbols to construct a format pattern. Use custom date formatting only for reports that are viewed in a single locale. Custom formats always display dates in the format you set. This format can be inappropriate for other locales. 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 customarily appear in day‑month‑year format, the date 01‑10‑06 is interpreted as October 1, 2006.
Table 7‑4 lists the specials symbols used to define custom date‑and‑time formats.
Table 7‑4 Symbols for defining custom date‑and‑time formats
Symbol
Description
Example
yy
Short year
08
yyyy
Long year
2008
MM
Month as a number
07
MMM
Short month name
Jul
MMMM
Full month name
July
d
Day in month
10
W
Week in month
2
w
Week in year
28
DD
Day in year
192
E
Short day of week
Thu
EEEE
Long day of week
Thursday
H
Hour in day (0 ‑ 23)
0
k
Hour in day (1 ‑ 24)
24
K
Hour in AM/PM (0 ‑ 11)
0
h
Hour in AM/PM (1 ‑ 12)
12
mm
Minutes
30
ss
Seconds
55
a
AM or PM
8:00:00AM
Table 7‑5 shows examples of custom formats and their effects on a date that is stored as April 15, 2006 12:15:30 PM.
Table 7‑5 Examples of custom date‑and‑time formats
Format pattern
Result of formatting
MM‑dd‑yy
04‑15‑06
E, M/d/yyyy
Fri, 4/15/2006
MMM d
Apr 15
MMMM
April
yyyy
2006
W
3 (the week in the month)
w
15 (the week in the year)
DD
105 (the day in the year)
h:mm:ss
12:15:30
Applying a custom string format
You can define a custom string format using special symbols to construct a format pattern. Table 7‑6 describes these symbols.
Table 7‑6 Symbols for defining custom string formats
Symbol
Description
@
Character placeholder. Each @ character displays a character in the string. If the string has fewer characters than the number of @ symbols that appear in the format pattern, spaces appear. Placeholders are filled from right to left, unless you specify an exclamation point (!) at the beginning of the format pattern.
&
Same as @, except if the string has fewer characters, spaces do not appear.
!
Specifies that placeholders are to be filled from left to right.
>
Converts string characters to uppercase.
<
Converts string characters to lowercase.
Table 7‑7 shows example results of custom string format patterns on string data.
Table 7‑7 Examples of custom string formats
Format pattern
Data in original format
Result of formatting
(@@@) @@@‑@@@@
6175551007
5551007
(617) 555‑1007
(   ) 555‑1007
(&&&) &&&‑&&&&
6175551007
5551007
(617) 555‑1007
() 555‑1007
!(@@@) @@@‑@@@@
6175551007
5551007
(617) 555‑1007
(555) 100‑7
!(&&&) &&&‑&&&&
6175551007
5551007
(617) 555‑1007
(555) 100‑7
!(@@@) @@@‑@@@@ + ext 9
5551007
(555) 100‑7    + ext 9
!(&&&) &&&‑&&&& + ext 9
5551007
(555) 100‑7 + ext 9
>&&&‑&&&&&‑&&
D1234567xy
D12‑34567‑XY
<&&&‑&&&&&‑&&
D1234567xy
d12‑34567‑xy