DecipherMiddleware

DateTime formatting using xp20:format-dateTime()

· 359 words · 2 minutes to read · ✍️ Pranav Davar
Categories: Oracle
Tags: OIC SOA XSLT JDeveloper

xs:dateTime Format 🔗

In XML, we generally use xs:dateTime(xs:xmlns=“http://www.w3.org/2001/XMLSchema") data type to store date time data. The generic representation of date time, that is supported by xs:dateTime in xml:

YYYY-MM-DDThh:mm:ss[.SSS][Z|(+|-)hh:mm]

Example: 🔗

2019-09-11T10:16:31.943+05:30

CodeDescriptionExample
YYYYrepresents a 4-digit year2019
MMrepresents a 2-digit month09
DDrepresents 2-digit date11
hhrepresents 2-digit hours10
mmrepresents minutes in 2-digits16
ssrepresents seconds in 2-digits31
SSSrepresents milliseconds943
Trepresents time separatorT
Zrepresents UTC time zone or 0 time zone offset
(+|-)hh:mm represents time zone offset+5:30

Few more valid examples: 2019-09-11T21:32:52, 2019-09-11T21:32:52+02:00, 2019-09-11T19:32:52Z, 2019-09-11T19:32:52+00:00, 2019-09-11T21:32:52.11179

While working with different systems, we may come across such systems, which require date time in some different formats other than default format as supported by xs:dateTime. To over come such scenarios, function is available in OIC(Oracle Integration Cloud) and Oracle SOA

Format DateTime 🔗

xp20:format-dateTime($dateTime as string, $format as string) xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"

$dateTime should contain date time value as per xs:dateTime data type as as string eg: ‘2019-09-11T10:16:31.943+05:30’

$format should contain output format to which we need to convert to. For e.g. if we want output to be ‘11/09/2019’ then value of $format should be [D01]/[M01]/[Y001].

xp20:format-dateTime('2019-09-11T10:16:31.943+05:30', '[D01]/[M01]/[Y001]')

To format current date time, we can use xp20:current-dateTime() in $dateTime

xp20:format-dateTime(xp20:current-dateTime(), '[D01]/[M01]/[Y001]')

Formatting Codes: 🔗

Below are some important codes which can be helpful in generating desired format for target application.

Sample dateTime: 2019-09-03T15:16:31.943+05:30

CodeDescriptionExample Output
[Y001]4 digit year2019
[Y01]2 digit year19
[M01]2 digit month09
[D01]2 digit date03
[H01]2 digit hour in 24 hour clock15
[h01]2 digit hour in 12 hour clock03
[m01]2-digit minutes16
[s01]2-digit seconds31
[f001]3-digit milliseconds943
[Z]Time zone offset in the form (+|-)hhmm+0530
[z]Time zone offset in the form GMT(+|-)hh:mmGMT+05:30
[Dwo]Word for ordinal value of daythird
[dwo]The day of the year, represented in ordinal wordssecond hundred and forty-sixth
[MNn]Capitalized month nameSeptember
[P]am/pmpm
[PX]Uppercase am/pmPM
[FNn]Capitalized weekday nameTuesday
[MNn,a-b]Capitalized month name having atleast “a” charcters and atmost “b” characters [MNn,3-3]:Sep