Message Sets: DateTime as string data

You can use a string of pattern letters to specify the dateTime format.

When you convert a date or time into a string, a format pattern must be applied that directs the conversion. Apply the format pattern to convert a date or time into a string, or to parse a string into a date or time.

During the conversion (for example, of a dateTime into a string), a pattern or a set of tokens is replaced with the equivalent source. The following diagram shows how a pattern is used to format a dateTime source to produce a character string output.

This diagram shows the output string that results from a dateTime source and a format pattern.

When a string is parsed (for example, when converting the string to a dateTime), the pattern or set of tokens is used to determine which part of the target dateTime is represented by which part of the string. The following diagram shows how this is done.

This diagram shows the dateTime output that results from a string data source and a format pattern.

Syntax

The expression pattern is defined by:

Read syntax diagramSkip visual syntax diagramsymbolstring
Where:
symbol
is a character in the set adDeEFGhHIkKmMsSTUwWyYzZ.
string
is a sequence of characters enclosed in single quotation marks. If a single quotation mark is required within the string, use two single quotation marks (").

Characters for formatting a dateTime as a string

The following table lists the characters that you can use in a pattern for formatting or parsing strings in relation to a dateTime. The table is followed by some notes that explain more about some of the examples in the table.

Symbol Meaning Presentation Examples
a am or pm marker Text Input am, AM, pm, PM. Output AM or PM
d day in month (1-31) Number 1, 20
dd day in month (01-31) Number 01, 31
D day in year (1-366) Number 3, 80, 100
DD day in year (01-366) Number 03, 80, 366
DDD day in year (001-366) Number 003
e day in week (1-7)1 Number 2
EEE day in week1 Text Tue
EEEE day in week1 Text Tuesday
F day of week in month (1-5)2 Number 2
G Era Text BC or AD
h hour in am or pm (1-12) Number 6
hh hour in am or pm (01-12) Number 06
H hour of day in 24 hour form (0-23)3 Number 7
HH hour of day in 24 hour form (00-23)3 Number 07
I ISO8601 Date/Time (up to yyyy-MM-dd'T'HH:mm:ss. SSSZZZ)4 Text 2006-10-07T12:06:56.568+01:00
IU ISO8601 Date/Time (similar to I, but ZZZ with output "Z" if the time zone is +00:00)4 Text 2006-10-07T12:06:56.568+01:00, 2003-12 -15T15:42:12.000Z
k hour of day in 24 hour form (1-24)3 Number 8
kk hour of day in 24 hour form (01-24)3 Number 08
K hour in am or pm (0-11) Number 9
KK hour in am or pm (00-11) Number 09
m minute Number 4
mm minute Number 04
M numeric month Number 5, 12
MM numeric month Number 05, 12
MMM named month Text Jan, Feb
MMMM named month Text January, February
s seconds10 Number 5
ss seconds10 Number 05
S decisecond5 Number 7
SS centisecond5 Number 70
SSS millisecond5 Number 700
SSSS 0.0001 second5 Number 7000
SSSSS 0.00001 second5 Number 70000
SSSSSS 0.000001 second5 Number 700000
T ISO8601 Time (up to HH:mm:ss.SSSZZZ)4 Text 12:06:56.568+01:00
TU ISO8601 Time (similar to T, but a time zone of +00:00 is replaced with 'Z')4 Text 12:06:56.568+01:00, 15:42:12.000Z
w week in year6 Number 7, 53
ww week in year6 Number 07, 53
W week in month7 Number 2
yy year8 Number 06
yyyy year8 Number 2006
YY year: use with week in year only6 Number 06
YYYY year: use with week in year only6 Number 2006
zzz time zone (abbreviated name)9 Text EST
zzzz time zone (full name) Text Eastern Standard Time
Z time zone (+/-n) Text +3
ZZ time zone (+/-nn) Text +03
ZZZ time zone (+/-nn:nn) Text +03:00
ZZZU time zone (as ZZZ, "+00:00" is replaced by "Z") Text +03:00, Z
ZZZZ time zone (GMT+/-nn:nn) Text GMT+03:00
ZZZZZ time zone (as ZZZ, but no colon) (+/-nnnn) Text +0300
' escape for text   'User text'
" (two single quotation marks) single quotation mark within escaped text   'o"clock'

The presentation of the dateTime object depends on the symbols that you specify.

  • Text: If you specify four or more of the symbols, the full form is presented. If you specify less than four, the short or abbreviated form, if it exists, is presented. For example, EEEE produces Monday, EEE produces Mon.
  • Number: The number of characters for a numeric dateTime component must be within the bounds of the corresponding formatting symbols. Repeat the symbol to specify the minimum number of digits required. The maximum number of digits permitted is the upper bound for a particular symbol. For example, day in month has an upper bound of 31; therefore, a format string of d allows the values 2 or 21 to be parsed but does not allow the values 32 or 210 to be parsed. On output, numbers are padded with zeros to the specified length. A year is a special case; see note 8. Fractional seconds are also a special case; see note 5.
  • Lenient dateTime checking: The parser converts out-of-band dateTime values to the appropriate in-band value. For example, the date 2005-05-32 is converted to 2005-06-01. Output of dateTimes always adheres to the symbol count. For example, a formatting string of yyyy-MM-dd (where '-' is the field separator) allows one or more characters to be parsed against MM and dd. This conversion allows dates such as 2006-01-123 and 2006-011-12, which are not valid, to be input. The value of 2006-01-123 is written as the date 2006-05-03, and the value of 2006-011-12 is written as the date 2006-11-12. The number of occurrences of the time zone formatting symbol Z applies only to the output dateTime format. White space is skipped over.
  • Physical Type: If you specify the Physical Type property of the dateTime object to be Packed Decimal, the only pattern formatting symbols that are valid are those that represent numbers; that is, those that have Number in the Presentation column of the table. No other characters are allowed in the format pattern. For example, yyyyMMdd is valid, but yyyyMMMdd is not valid because MM is a numeric representation of the month, and MMM is a textual representation of the month.
  • Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] are treated as quoted text. For example, characters like colon (:), comma (,), period (.), the number sign (hash or pound, #), the at sign (@), and space are displayed in the resulting time text even if they are not enclosed within single quotation marks.
  • You can create formatting strings that produce unpredictable results; therefore, you must use these symbols with care. For example, if you specify dMyyyy, it is impossible to distinguish between day, month, and year. dMyyyy tells the integration node that a minimum of one character represents the day, a minimum of one character represents the month, and four characters represent the year. Therefore 3112006 might be interpreted as 3/11/2006 or as 31/1/2006.
Notes: The following notes apply to the preceding table.
  1. The day in week field is the numeric offset into a week and varies according to the value of the physical message set property First Day of Week. For example, the third day in the week is Wednesday if the physical message set property First Day of Week is set to Monday.
  2. 12th July 2006 is the second Wednesday in July and can be expressed as 2006 July Wednesday 2 using the format string yyyy MMMM EEEE F. Note that this format does not represent the Wednesday in week 2 of July 2006, which is 5th July 2006; the format string for this is yyyy MMMM EEEE W.
  3. 24-hour fields might result in an ambiguous time, if specified with a conflicting am/pm field.
  4. See ISO8601, I and T DateTime tokens.
  5. Fractional seconds are represented by uppercase S. The length must implicitly match the number of format symbols on input. The format string ss SSS or ss.SSS, for example, represents seconds and milliseconds. However, the format string ss.sss represents a repeated field (of seconds); the value after the period (.) is taken as a seconds field, not as fractional seconds. The output is truncated to the specified length.
  6. The start of a year typically falls in the middle of a week. If the number of days in that week is less than the value specified by the physical message set property Days in First Week of Year, the week is considered to be the last week of the previous year; in this case, week 1 starts some days into the new year. Otherwise, the week is considered to be the first week of the new year; in this case, week 1 starts some days before the new year. For example, Monday of week 1 in 2004 (2004 01 Monday, where Days in First Week of Year = 4 and First Day of Week = Monday ) using format string YYYY ww EEEE is in fact 29th December 2003. If you use Y, the day of week (E) and week in year (w) are adjusted if necessary to indicate that the date falls in the previous year.

    If you use the lowercase y symbol, the adjustment is not done and unpredictable results might occur for dates around year end. For example, if the string 2002 01 Monday is formatted:

    • Monday of week 1 in 2002 using format string YYYY ww EEEE is correctly interpreted as 31st December 2001
    • Monday of week 1 in 2002 using format string yyyy ww EEEE is incorrectly interpreted as 30th December 2002

    Use Y together with w only; if you do not specify w, use y.

  7. The first and last week in a month might include days from neighboring months. For example, Monday 31st July 2006 can be expressed as Monday in week one of August 2006, which is 2006 08 1 Monday using format string yyyy MM W EEEE.
  8. Year is handled as a special case:
    • On output, if the count of y is 2, the year is truncated to 2 digits. For example, if yyyy produces 2006, yy produces 06.
    • On input, for 2-digit years, the physical message set property of Start of century for 2 digit years is used to determine the century. For example, if Start of century for 2 digit years is set to 53, year 97 is 1997, year 52 is 2052, and year 53 is 1953.
  9. Using the zzz option can have ambiguous results. For example, BST can be interpreted as Bangladesh Standard Time or British Summer Time. For compatibility reasons, IBM® App Connect Enterprise uses the former interpretation.

    To avoid these problems, use the zzzz option with a well-defined name; for example, Europe/London, Asia/Dhaka, or America/Los_Angeles.

  10. Seconds s & ss, must be in the range 0-59. If you need to construct a TIMESTAMP representing the time during a leap second, where the value being created or cast uses the value 60 for seconds, you must handle this case within your ESQL code. The CURRENT_ datetime functions (for example, CURRENT_TIME) within the product never produce a time where the seconds value falls outside of the 0-59 range.

ISO8601, I and T DateTime tokens

If your dateTime values comply with the ISO8601:2000 'Representation of dates and times' standard, consider using the formatting symbols I and T, which match the following subset of the ISO8601 standard.

  • The restricted profile as proposed by the W3C at http://www.w3.org/TR/NOTE-datetime
  • Truncated representations of calendar dates, as specified in section 5.2.1.3 of ISO8601:2000
    • Basic format (subsections c, e, and f)
    • Extended format (subsections a, b, and d)

Use the formatting symbols I and T only on their own:

  • The I formatting symbol matches any dateTime string that conforms to the supported subset.
  • The T formatting symbol matches any dateTime string that conforms to the supported subset that consists of a time portion only.

The following table shows how the output form relates to the logical data type.

Logical model data type ESQL data type Output form
xsd:dateTime TIMESTAMP or GMTTIMESTAMP yyyy-MM-dd'T'HH:mm:ss.SSSZZZ
xsd:date DATE yyyy-MM-dd
xsd:gYear INTERVAL yyyy
xsd:gYearMonth INTERVAL yyyy-MM
xsd:gMonth INTERVAL --MM
xsd:gmonthDay INTERVAL --MM-dd
xsd:gDay INTERVAL ---dd
xsd:time TIME / GMTTIME 'T'HH:mm:ss.SSSZZZ
Note:
  • On input, both I and T accept both '+00:00' and 'Z' to indicate a zero time difference from Coordinated Universal Time (UTC), but on output they always generate '+00:00'. If you want 'Z' to always be generated on output, use the IU or TU formatting symbols instead.
  • ZZZ always writes '+00:00' to indicate a zero time difference from Coordinated Universal Time (UTC). If you want 'Z' to always be generated on output, use ZZZU instead.

Using the input UTC format on output

An element or attribute of logical type xsd:dateTime or xsd:time that contains a dateTime as a string can specify Coordinated Universal Time (UTC) by using either the Z symbol or time zone +00:00. On input, the MRM parser remembers the UTC format of such elements and attributes. On output, you can specify whether Z or +00:00 is displayed by using the Default DateTime Format property of the element or attribute. Alternatively, you can preserve the input UTC format by selecting the message set property Use input UTC format on output. If this property is selected, the UTC format is preserved in the output message and overrides the format that is implied by the dateTime format property.

Examples

The following table shows a few examples of dateTime formats.

Format pattern Result
"yyyy.MM.dd 'at' HH:mm:ss ZZZ" 2006.07.10 at 15:08:56 -05:00
"EEE, MMM d, "yy" Wed, July 10, '06
"h:mm a" 8:08 PM
"hh o"clock a, ZZZZ" 09 o'clock AM, GMT+09:00
"K:mm a, ZZZ" 9:34 AM, -05:00
"yyyy.MMMMM.dd hh:mm aaa" 1996.July.10 12:08 PM