Date and Time Functions
There are some functions in the XPath formula builder that allow you to parse or format strings that represent dates and times.
These functions are:
• | format-dateTime(<<format>>, <<dateTime>>) |
• | format-date(<<format>>, <<date>>) |
• | format-time(<<format>>, <<time>>) |
• | parse-dateTime(<<format>>, <<string>>) |
• | parse-date(<<format>>, <<string>>) |
• | parse-time(<<format>>, <<string>>) |
The format parameter of these functions is based on the format patterns available for the java.text.SimpleDateFormat Java class. In the format parameter, unquoted alphabetic characters from A to Z and a to z represent the components of the date or time string. You can include non-pattern alphabetic characters in the string by quoting the text with single quotes. To include a single quote, use ’’.
The following table describes the alphabetic characters and their associated presentation in a date or time string.
character | Description | Example |
---|---|---|
G |
Era. Four or more Gs return the full name of the era. |
AD |
y | year. yy returns two-digit year. | 2003; 03 |
M |
Month in a year. Three or more Ms return text name. |
August; Aug; 08 |
w | Week in a year | 48 |
W | Week in a month | 3 |
D | Day in a year | 253 |
d | Day in a month | 25 |
F | Day of a week in a month | 2 |
E |
Day in week. Four or more Es return the full name of the weekday. |
Friday; Fri |
a | AM/PM marker. Four or more as return the full name. | AM |
H | Hour in a day (0-23) | 22 |
k | Hour in a day (1-24) | 2 |
K | Hour in AM/PM (0-11) | 10 |
h | Hour in AM/PM (1-12) | 4 |
m | Minute in an hour | 54 |
s | Second in a minute | 48 |
S | Milliseconds | 456 |
z | Time zone represented as a GMT offset | GMT-08:00 |
Z | RFC 822 four-digit time zone format | -0800 |
all other letters | Reserved | - |
For any format pattern letter that returns a numeric value (for example, w, h, and m), the number of letters in the format pattern represents the minimum number of digits. For formatting functions, if the date or time has fewer digits than the number of pattern letters, the output is padded with zeros. For parsing functions, when the date or time has fewer digits than the number of characters in the format pattern, the extra characters are ignored, unless they are needed to determine the boundaries of adjacent fields.
The following table illustrates some example date and time format patterns and the resulting string.
Date-Time Pattern | Result |
"yyy.MM.dd G ’at’ HH:mm:ss" | 2003.3.11 AD at 09:43:56 |
"EEE, MMM d, ’’yy" | Tue, Mar 11, ’03 |
"hh ’o’’clock’ a, zzzz" | 9 o’clock AM, GMT-8:00 |
"K:mm a" | 0:08 PM |
"yyMMddHHmmssZ" | 010704120856-700 |