This section gives information on how you can specify the dateTime format using a string of pattern letters.
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.
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.
The expression pattern is defined by:
.------------. V | >>---+-symbol-+-+---------------------------------------------->< '-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 what symbols you specify.
If you use the y symbol, the adjustment is not done and unpredictable results might occur for dates around the end of the year. For example, if the string "2005 01 Monday" is formatted:
To avoid these problems, use the zzzz option with a well-defined name; for example, Europe/London, Asia/Dhaka, or America/Los_Angeles.
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.
Use the formatting symbols I and T only on their own:
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 |
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.
When the broker is running in a time zone other than GMT, it calculates the daylight saving time (DST) offset on times that are supplied to it by the CAST function. For CAST to calculate the offset correctly, the time passed into CAST must have a time zone associated with it, as a Z parameter. If no time zone is associated with the value passed, the time is converted into GMT time; it is not treated as a local time stamp.
Also, when you use CAST to cast a string to a time value, the DST offset is calculated using the current system date. To cast a string to a time variable and calculate DST for a specific date, you must also specify the date.
DECLARE castTime TIME;
SET castTime = CAST (timeValue AS TIME FORMAT timePattern)
The
time is not converted into GMT again if the castTime variable is used
in any subsequent code, for example CAST(castDate, castTime AS GMTTIMESTAMP);
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 |
In MRM it is possible to define an element that has the logical type of dateTime.
When a dateTime element is parsed, a field is created in the message tree that has the ESQL datatype of CURRENT_TIME or CURRENT_TIMESTAMP. However, the CURRENT_TIME and CURRENT_TIMESTAMP data types do not have the functionality to store timezone information, and the MRM does not adjust the time according to the input timezone and the timezone of the broker.
Although the CURRENT_TIME and CURRENT_TIMESTAMP data types cannot store timezone information, the MRM stores this information as part of the underlying field. This means that if the field is copied between message trees, the timezone information is copied with it, allowing this information to be preserved on output.
Note that the information is preserved only if the field is copied to a field of the same name.
However, if any new field is derived from the original field, the new field does not have the timezone information. This means that if such a field is cast as a character, the new field assumes the timezone of the broker, but its value is not adjusted for any difference between the input timezone and the timezone of the broker.
For example, an input dateTime element containing 2009-02-20T06:08:07-08:00 could be copied from the input message tree to the output message tree and appear in an output message in exactly the same format. However, if the element is cast as character, using format IU, by a broker running GMT the result would be 2009-02-20T06:08:07.000Z.