Because the Date and Time functions category has too many functions, I decide to break this blog post into different parts, so welcome to the third part!
Overview
Date and Time functions are used to perform a variety of operations over Dates, such as retrieving the current date and time or adding dates, etc. If you come from the BizTalk Server background or are migrating BizTalk Server projects, they are the equivalent of Date/Time Functoids inside BizTalk Mapper Editor.
Available Functions
The Date and Time functoids are:
- Add days: Adds a positive or negative number of days to the specified timestamp. Returns a timestamp that’s respectively later or earlier than the specified timestamp.
- Add DayTime to Date: Adds a positive or negative DayTime duration to the specified Date value (xs:date). Returns a Date that’s respectively after or before the specified Date.
- Add DayTime to DateTime: Adds a positive or negative DayTime duration to the specified DateTime value (xs:dateTime). Returns a DateTime that’s respectively after or before the specified DateTime.
- Add DayTime to Time: Adds a positive or negative DayTime duration to the specified Time value (xs:time). Returns a Time that’s respectively after or before the specified Time. Durations that wrap around past midnight also return an earlier Time.
- Add YearMonth to DateTime: Adds a positive or negative YearMonth duration to the specified DateTime value (xs:dateTime). Returns a DateTime that’s respectively after or before the specified DateTime.
- Adjust Date: Adjusts the specified Date value (xs:date) to the current or dynamic time zone.
- Adjust DateTime: Adjusts the specified DateTime value (xs:dateTime) to the current or dynamic time zone.
- Adjust Time: Adjusts the specified Time value (xs:time) to the current or dynamic time zone.
- Current date: Returns the current date in YYYY-MM-DD format.
- Current DateTime value: Returns the current date and time in YYYY-MM-DDThh:mm:ss format.
- Current time: Returns the current date and time in YYYY-MM-DDThh:mm:ss format.
- DateTime: Creates and returns a DateTime value based on the specified Date and Time.
- Day from Date: Returns the day from the specified Date value (xs:date).
- Day from DateTime: Returns the day from the specified DateTime value (xs:dateTime).
- Equal Date: Returns true or false based on whether the specified Date values are equal.
- Equal DateTime: Returns true or false based on whether with the specified DateTime values are equal.
- Equal Day: Returns true or false based on whether the specified Day values (xs:gDay) are equal with the same starting time when the day values are in the same month and year.
- Equal Month: Returns true or false based on whether the specified Month values (xs:gMonth) have the same starting time when the month values are in the same year.
- Equal MonthDay: Returns true or false based on whether the specified MonthDay values (xs:gMonthDay) are equal with the same starting time when the day values are in the same year.
- Equal Time: Returns true or false based on whether the specified Time values are equal.
- Equal Year: Returns true or false based on whether the specified Year values (xs:gYear) have the same starting time.
- Equal YearMonth: Returns true or false based on whether the specified YearMonth values (xs:gYearMonth) are the same.
- Greater Date: Returns true or false based on whether the first Date value is later than the second Date value.
- Greater DateTime: Returns true or false based on whether the first DateTime value is later than the second DateTime value.
- Greater Time: Returns true or false based on whether the first Time value is later than the second Time value.
- Hours from DateTime: Returns the hours from the specified DateTime value (xs:dateTime).
- Hours from Time: Returns the hours from the specified Time value (xs:time).
- Less Date: Returns true or false based on whether the first Date value is earlier than the second Date value.
- Less DateTime: Returns true or false based on whether the first DateTime value is earlier than the second DateTime value.
- Less Time: Returns true or false based on whether the first Time value is earlier than the second Time value.
- Minutes from DateTime: Returns the minutes from the specified DateTime value (xs:dateTime).
- Minutes from Time: Returns the minutes from the specified Time value (xs:time).
- Month from Date: Returns the month from the specified Date value (xs:date).
- Month from DateTime: Returns the month from the specified DateTime value (xs:dateTime).
- Seconds from DateTime: Returns the seconds from the specified DateTime value (xs:dateTime).
- Seconds from Time: Returns the seconds from the specified Time value (xs:time).
- Subtract Dates: Returns the DayTimeDuration value (xs:dayTimeDuration) representing the elapsed time between the starting times for the specified Date values.
- Subtract DateTimes: Returns a DayTimeDuration value (xs:dayTimeDuration) representing the elapsed time between the specified DateTime values..
- Subtract DateTime from Date: Subtracts a positive or negative DayTime duration from the specified Date value (xs:date). Returns a Date that’s respectively before or after the specified Date..
- Subtract DateTime from DateTime: Subtracts a positive or negative DayTime duration from the specified DateTime value (xs:dateTime). Returns a DateTime that’s respectively before or after the specified DateTime.
- Subtract DateTime from Time: Subtracts a positive or negative Time duration from the specified Time value (xs:time). Returns a Time that’s respectively before or after the specified Time. A duration that wraps around past midnight also returns a later Time.
- Subtract Times: Returns a DayTimeDuration value (xs:dayTimeDuration) representing the elapsed time between the specified Time values, which are treated as times on the same date.
- Subtract YearMonth from Date: Subtracts a positive or negative YearMonth duration from the specified Date value (xs:date). Returns a Date that’s respectively before or after the specified Date.
- Subtract YearMonth from DateTime: Subtracts a positive or negative YearMonth duration from the specified DateTime value (xs:dateTime). Returns a DateTime that’s respectively before or after the specified DateTime.
- Time zone from Date: Returns the time zone from the specified Date value (xs:date).
- Time zone from DateTime: Returns the time zone from the specified DateTime value (xs:dateTime).
- Time zone from Time: Returns the time zone from the specified Time value (xs:time).
- Year from Date: Returns the year from the specified Date value (xs:date).
- Year from DateTime: Returns the year from the specified DateTime value (xs:dateTime).
Greater Date
This function states that it will return true or false based on whether the first Date value is later than the second Date value.
Behind the scenes, this function is translated to the following XPath expression: xs:date($arg1) > xs:date($arg2)
- xs:date($arg1) > xs:date($arg2) as xs:boolean
Rules:
- Returns
true
if and only if the starting instant of$arg1
is greater than the starting instant of$arg2
. Returnsfalse
otherwise. - The
$arg
1 and $arg2 need to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ.
Sample:
- The following Data Mapper transformation rule: is-greater-than-date(“2013-07-28”, “2013-07-29”) will be translated to {xs:date(‘2013-07-28’) > xs:date(‘2013-07-29’)} and the return will be false.
Greater DateTime
This function states that it will return true or false based on whether the first DateTime value is later than the second DateTime value.
Behind the scenes, this function is translated to the following XPath expression: xs:dateTime($arg1) > xs:dateTime($arg2)
- xs:dateTime($arg1) > xs:dateTime($arg2) as xs:boolean
Rules:
- Returns
true
if the first argument represents a later instant in time than the second argument. Returnsfalse
otherwise. - The
$arg
1 and $arg2 need to be an xs:dateTime in the following format yyyy-MM-DDTHH:mm:ss or yyyy-MM-DDTHH:mm:ss-hh:mm.
Sample:
- The following Data Mapper transformation rule: is-greater-than-datetime(“2023-07-25T12:00:00+01:00”, “2023-07-25T13:00:00+01:00”) will be translated to {xs:dateTime(‘2023-07-25T12:00:00+01:00’) > xs:dateTime(‘2023-07-25T13:00:00+01:00’)} and the return will be false.
Greater Time
This function states that it will return true or false based on whether the first Time value is later than the second Time value.
Behind the scenes, this function is translated to the following XPath expression: xs:time($arg1) > xs:time($arg2)
- xs:time($arg1) > xs:time($arg2) as xs:boolean
Rules:
- Returns
true
if the firstxs:time
value represents a later instant in time than the second, when both are treated as being times on the same date, before adjusting the timezone. - The
to be an xs:time in the following format HH:mm:ss or HH:mm:ss-hh:mm.$arg
1 and $arg2 need
Sample:
- The following Data Mapper transformation rule: is-greater-than-time(“01:00:00”, “02:00:00”) will be translated to {xs:time(’01:00:00′) > xs:time(’02:00:00′)} and the return will be false.
Hours from DateTime
This function states that it will return the hours from the specified DateTime value (xs:dateTime).
Behind the scenes, this function is translated to the following XPath function: hours-from-dateTime($arg1)
fn:hours-from-dateTime
($arg as xs:dateTime?
)as xs:integer?
Rules:
- Returns the hours component of an
xs:dateTime
without adjusting the timezone. - The
$arg
1 needs to be an xs:dateTime in the following format yyyy-MM-DDTHH:mm:ss or yyyy-MM-DDTHH:mm:ss-hh:mm.
Sample:
- The expression
fn:hours-from-dateTime(xs:dateTime("1999-05-31T08:20:00-05:00"))
returns8
.
Hours from Time
This function states that it will return the hours from the specified Time value (xs:time).
Behind the scenes, this function is translated to the following XPath function: hours-from-time($arg1)
fn:hours-from-time
($arg as xs:time?
)as xs:integer?
Rules:
- Returns the hours component of an
xs:time
without adjusting the timezone. - The
$arg
1 needs to be an xs:time in the following format HH:mm:ss or HH:mm:ss-hh:mm.
Sample:
- The following Data Mapper transformation rule: is-less-than-datetime(“2023-07-25T12:00:00+01:00”, “2023-07-25T13:00:00+01:00”) will be translated to {xs:dateTime(‘2023-07-25T12:00:00+01:00’) > xs:dateTime(‘2023-07-25T13:00:00+01:00’)} and the return will be false.
Less Date
This function states that it will return true or false based on whether the first Date value is earlier than the second Date value.
Behind the scenes, this function is translated to the following XPath expression: xs:date($arg1) < xs:date($arg2)
- xs:date($arg1) < xs:date($arg2) as xs:boolean
Rules:
- Returns
true
if and only if the starting instant of$arg1
is less than the starting instant of$arg2
. Returnsfalse
otherwise. - The
$arg
1 and $arg2 need to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ.
Sample:
- The following Data Mapper transformation rule: is-less-than-date(“2023-07-28”, “2023-07-29”) will be translated to {xs:date(‘2023-07-28’) < xs:date(‘2023-07-29’)} and the return will be true.
Less DateTime
This function states that it will return true or false based on whether the first DateTime value is earlier than the second DateTime value.
Behind the scenes, this function is translated to the following XPath function: xs:dateTime($arg1) < xs:dateTime($arg2)
- xs:dateTime($arg1) < xs:dateTime($arg2) as xs:boolean
Rules:
- Returns
true
if the first argument represents an earlier instant in time than the second argument. - The
$arg
1 and $arg2 need to be an xs:dateTime in the following format yyyy-MM-DDTHH:mm:ss or yyyy-MM-DDTHH:mm:ss-hh:mm.
Sample:
- The following Data Mapper transformation rule: is-less-than-datetime(“2023-07-25T12:00:00+01:00”, “2023-07-25T13:00:00+01:00”) will be translated to {xs:dateTime(‘2023-07-25T12:00:00+01:00’) < xs:dateTime(‘2023-07-25T13:00:00+01:00’)} and the return will be true.
Less Time
This function states that it will return true or false based on whether the first Time value is earlier than the second Time value.
Behind the scenes, this function is translated to the following XPath function: xs:time($arg1) < xs:time($arg2)
- xs:time($arg1) < xs:time($arg2) as xs:boolean
Rules:
- Returns
true
if the firstxs:time
value represents an earlier instant in time than the second, when both are treated as being times on the same date, before adjusting the timezone. - The
to be an xs:time in the following format HH:mm:ss or HH:mm:ss-hh:mm.$arg
1 and $arg2 need
Sample:
- The following Data Mapper transformation rule: is-less-than-time(“12:00:00”, “13:00:00”) will be translated to {xs:time(’12:00:00′) < xs:time(’13:00:00′)} and the return will be true.
Minutes from DateTime
This function states that it will return the minutes from the specified DateTime value (xs:dateTime).
Behind the scenes, this function is translated to the following XPath function: minutes-from-dateTime($arg)
fn:minutes-from-dateTime
($arg as xs:dateTime?
)as xs:integer?
Rules:
- The function returns an
xs:integer
value between 0 and 59, both inclusive, representing the minute component defined in the$arg
without adjusting the timezone. - The
$arg
needs to be an xs:dateTime in the following format yyyy-MM-DDTHH:mm:ss or yyyy-MM-DDTHH:mm:ss-hh:mm.
Sample:
- The expression
fn:minutes-from-dateTime(xs:dateTime("1999-05-31T13:30:00+05:30"))
returns30
.
Minutes from Time
This function states that it will return the minutes from the specified Time value (xs:time).
Behind the scenes, this function is translated to the following XPath function: minutes-from-time($arg)
- number($arg as xs:anyAtomicType?) as xs:boolean
Rules:
- Returns the minutes component of an
xs:time
without adjusting the timezone. - The
$arg
needs to be an xs:time in the following format HH:mm:ss or HH:mm:ss-hh:mm.
Sample:
- The expression
fn:minutes-from-time(xs:time("13:00:00Z"))
returns0
.
Month from Date
This function states that it will return the month from the specified Date value (xs:date).
Behind the scenes, this function is translated to the following XPath function: month-from-date($arg)
fn:month-from-date
($arg as xs:date?
)as xs:integer?
Rules:
- The function returns an
xs:integer
between 1 and 12, both inclusive, representing the month component in the local value of$arg
. - The
$arg
needs to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ.
Sample:
- The expression
fn:month-from-date(xs:date("1999-05-31"))
returns5
Month from DateTime
This function states that it will return the month from the specified DateTime value (xs:dateTime).
Behind the scenes, this function is translated to the following XPath function: month-from-dateTime($arg)
- number($arg as xs:anyAtomicType?) as xs:boolean
Rules:
- The function returns an
xs:integer
between 1 and 12, both inclusive, representing the month defined on the$arg without adjusting the timezone
. - The
$arg
needs to be an xs:dateTime in the following format yyyy-MM-DDTHH:mm:ss or yyyy-MM-DDTHH:mm:ss-hh:mm.
Sample:
- The expression
fn:month-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00"))
returns5
.
Stay tuned for the fourth part of this blog post.
Hope you find this helpful! So, if you liked the content or found it useful and want to help me write more, you can buy (or help buy) my son a Star Wars Lego!