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 fourth 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).
Seconds from DateTime
This function states that it will return the seconds from the specified DateTime value (xs:dateTime).
Behind the scenes, this function is translated to the following XPath function: seconds-from-dateTime($ard)
fn:seconds-from-dateTime($arg as xs:dateTime?) as xs:decimal?
Rules:
The function returns an xs:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds defined in $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:seconds-from-dateTime(xs:dateTime("1999-05-31T13:20:32-05:00")) returns 32.
Seconds from Time
This function states that it will return the seconds from the specified Time value (xs:time).
Behind the scenes, this function is translated to the following XPath function: seconds-from-time($arg)
fn:seconds-from-time($arg as xs:time?) as xs:decimal?
Rules:
the function returns an xs:decimal value greater than or equal to zero and less than 60, representing the seconds and fractional seconds defined in $arg 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:seconds-from-time(xs:time("13:20:10.5")) returns 10.5.
Subtract Dates
This function states that it will return the DayTimeDuration value (xs:dayTimeDuration) representing the elapsed time between the starting times for the specified Date values.
Behind the scenes, this function is translated to the following XPath expression: xs:dayTimeDuration(xs:date($arg1) – xs:date($arg2))
xs:dayTimeDuration(xs:date($arg1) – xs:date($arg2)) as xs:dayTimeDuration
Rules:
If the starting instant of $arg1 precedes in time the starting instant of $arg2, then the returned value is a negative duration.
Returns the xs:dayTimeDuration (for example, “PT2H12M”) that corresponds to the elapsed time between the starting instant of $arg1 and the starting instant of $arg2.
The $arg1 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: subtract-dates(“2023-07-28”, “1978-04-04”) will be translated to {xs:dayTimeDuration(xs:date(‘2023-07-28’) – xs:date(‘1978-04-04’))} and the return will be P16551D.
Subtract DateTimes
This function states that it will return a DayTimeDuration value (xs:dayTimeDuration) representing the elapsed time between the specified DateTime values.
Behind the scenes, this function is translated to the following XPath expression: xs:dayTimeDuration(xs:dateTime($arg1) – xs:dateTime($arg2))
xs:dayTimeDuration(xs:dateTime($arg1) – xs:dateTime($arg2)) as xs:dayTimeDuration
Rules:
If the normalized value of $arg1 precedes in time the normalized value of $arg2, then the returned value is a negative duration.
Returns an xs:dayTimeDuration representing the amount of elapsed time between the instants arg2 and arg1.
The $arg1 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: subtract-datetimes(“2023-07-28T23:00:00”, “1978-04-04T10:30:00”) will be translated to {xs:dayTimeDuration(xs:dateTime(‘2023-07-28T23:00:00’) – xs:dateTime(‘1978-04-04T10:30:00’))} and the return will be P16551DT12H30M.
Subtract DateTime from Date
This function states that it will subtract 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.
Behind the scenes, this function is translated to the following XPath expression: xs:date(xs:date($arg1) – xs:dayTimeDuration($arg2))
xs:date(xs:date($arg1) – xs:dayTimeDuration($arg2)) as xs:date
Rules:
Returns the xs:date that is a given duration before a specified xs:date (or after, if the duration is negative).
The $arg1 needs to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ.
The $arg1 needs to be an xs:dayTimeDuration in the ISO 8601 format. ISO-8601 standard was created to elaborate crystal clear language to talk about dates and periods and avoid misinterpretation. Where Duration (“how long“) is represented with the format P[n]Y[n]M[n]DT[n]H[n]M[n]S, where n is a number.
Sample:
The following Data Mapper transformation rule: subtract-daytime-from-date(“2023-07-28”, “P16551D”) will be translated to {xs:date(xs:date(‘2023-07-28’) – xs:dayTimeDuration(‘P16551D’))} and the return will be 1978-04-04.
Subtract DateTime from DateTime
This function states that it will subtract 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.
Behind the scenes, this function is translated to the following XPath expression: xs:dateTime(xs:dateTime($arg1) – xs:dayTimeDuration($arg2))
xs:dateTime(xs:dateTime($arg1) – xs:dayTimeDuration($arg2)) as xs:dateTime
Rules:
Returns the xs:dateTime that is a given duration before a specified xs:dateTime (or after, if the duration is negative).
The $arg1 needs to be an xs:dateTime in the following format yyyy-MM-DDTHH:mm:ss or yyyy-MM-DDTHH:mm:ss-hh:mm.
The $arg1 needs to be an xs:dayTimeDuration in the ISO 8601 format. ISO-8601 standard was created to elaborate crystal clear language to talk about dates and periods and avoid misinterpretation. Where Duration (“how long“) is represented with the format P[n]Y[n]M[n]DT[n]H[n]M[n]S, where n is a number.
Sample:
The following Data Mapper transformation rule: subtract-daytime-from-datetime(“2023-07-28T23:00:00”, “P16551DT12H30M”) will be translated to {xs:dateTime(xs:dateTime(‘2023-07-28T23:00:00’) – xs:dayTimeDuration(‘P16551DT12H30M’))} and the return will be 1978-04-04T10:30:00.
Subtract DateTime from Time
This function states that it will subtract 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.
Behind the scenes, this function is translated to the following XPath expression: xs:time(xs:time($arg1) – xs:dayTimeDuration($arg2))
xs:time(xs:time($arg1) – xs:dayTimeDuration($arg2)) as xs:time
Rules:
Returns the xs:time value that is a given duration before a specified xs:time (or after, if the duration is negative or causes wrap-around past midnight)
The $arg1 needs to be an xs:time in the following format HH:mm:ss or HH:mm:ss-hh:mm.
The $arg1 needs to be an xs:dayTimeDuration in the ISO 8601 format. ISO-8601 standard was created to elaborate crystal clear language to talk about dates and periods and avoid misinterpretation. Where Duration (“how long“) is represented with the format P[n]Y[n]M[n]DT[n]H[n]M[n]S, where n is a number.
Sample:
The following Data Mapper transformation rule: subtract-daytime-from-time(“11:00:00”, “PT30M”) will be translated to {xs:time(xs:time(’11:00:00?) – xs:dayTimeDuration(‘PT30M’))} and the return will be 10:30:00.
Subtract Times
This function states that it will return a DayTimeDuration value (xs:dayTimeDuration) representing the elapsed time between the specified Time values, which are treated as times on the same date.
Behind the scenes, this function is translated to the following XPath expression: xs:dayTimeDuration(xs:time($arg1) – xs:time($arg2))
xs:dayTimeDuration(xs:time($arg1) – xs:time($arg2)) as xs:dayTimeDuration
Rules:
Returns the xs:dayTimeDuration that corresponds to the elapsed time between the values of $arg2 and $arg1 treated as times on the same date.
The $arg1 and $arg2 need 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: subtract-times(“10:30:00”, “10:00:00”) will be translated to {xs:dayTimeDuration(xs:time(’10:30:00?) – xs:time(’10:00:00?))} and the return will be PT30M.
Subtract YearMonth from Date
This function states that it will subtract 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.
Behind the scenes, this function is translated to the following XPath expression: xs:date(xs:date($arg1) – xs:yearMonthDuration($arg2))
xs:date(xs:date($arg1) – xs:yearMonthDuration($arg2)) as xs:date
Rules:
Returns the xs:date that is a given duration after a specified xs:date (or before, if the duration is negative).
The $arg1 needs to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ.
The $arg2 needs to be an interval in ISO 8601 format. ISO-8601 standard was created to elaborate crystal clear language to discuss dates and periods and avoid misinterpretation. Where Duration (“how long“) is represented with the format P[n]Y[n], where n is a number – xs:yearMonthDuration.
Sample:
The following Data Mapper transformation rule: subtract-yearmonth-from-date(“2023-07-28”, “P1Y”) will be translated to {xs:date(xs:date(‘2023-07-28’) – xs:yearMonthDuration(‘P1Y’))} and the return will be 2022-07-28.
Subtract YearMonth from DateTime
This function states that it will subtract 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.
Behind the scenes, this function is translated to the following XPath expression: xs:dateTime(xs:dateTime($arg1) – xs:yearMonthDuration($arg2)
xs:dateTime(xs:dateTime($arg1) – xs:yearMonthDuration($arg2) as xs:dateTime
Rules:
Returns the xs:dateTime that is a given duration before a specified xs:dateTime (or after, if the duration is negative).
The $arg1 needs to be an xs:dateTime in the following format yyyy-MM-DDTHH:mm:ss or yyyy-MM-DDTHH:mm:ss-hh:mm.
The $arg2 needs to be an interval in ISO 8601 format. ISO-8601 standard was created to elaborate crystal clear language to discuss dates and periods and avoid misinterpretation. Where Duration (“how long“) is represented with the format P[n]Y[n], where n is a number – xs:yearMonthDuration.
Sample:
The following Data Mapper transformation rule: subtract-yearmonth-from-datetime(“2023-07-28T12:00:00”, “P1Y”) will be translated to {xs:dateTime(xs:dateTime(‘2023-07-28T12:00:00’) – xs:yearMonthDuration(‘P1Y’))} and the return will be 2022-07-28T12:00:00.
Stay tuned for the fifth 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!
Author: Sandro Pereira
Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc.
He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.
View all posts by Sandro Pereira
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. Returns false otherwise.
The $arg1 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. Returns false otherwise.
The $arg1 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 first xs: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 $arg1 and $arg2 need 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-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 $arg1 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")) returns 8.
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 $arg1 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. Returns false otherwise.
The $arg1 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 $arg1 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 first xs: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 $arg1 and $arg2 need 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-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")) returns 30.
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")) returns 0.
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")) returns 5
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")) returns 5.
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!
Author: Sandro Pereira
Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc.
He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.
View all posts by Sandro Pereira
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 second 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).
DateTime
This function states that it will create and returns a DateTime value based on the specified Date and Time.
Behind the scenes, this function is translated to the following XPath function: dateTime(xs:date($arg1), xs:time($arg1))
dateTime(xs:date($arg1), xs:time($arg1)) as xs:dateTime
Rules:
The $arg1 needs to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ.
The $arg2 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: datetime(“2023-07-27”, “12:00:00”) will be translated to {dateTime(xs:date(‘2023-07-27?), xs:time(’12:00:00’))} and the return will be 2023-07-27T12:00:00
Day from Date
This function states that it will return the day from the specified Date value (xs:date).
Behind the scenes, this function is translated to the following XPath function: day-from-date(xs:date($arg))
fn:day-from-date($arg as xs:date?) as xs:integer?
Rules:
The function returns an xs:integer between 1 and 31, both inclusive, representing the day component in the localized value of $arg.
The $arg needs to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ.
Sample:
The following Data Mapper transformation rule: day-from-date(“2023-07-27”) will be translated to {day-from-date(xs:date(‘2023-07-27’))} and the return will be 27.
Day from DateTime
This function states that it will return the day from the specified DateTime value (xs:dateTime).
Behind the scenes, this function is translated to the following XPath function: day-from-dateTime(xs:dateTime($arg))
fn:day-from-dateTime($arg as xs:dateTime?) as xs:integer?
Rules:
The function returns an xs:integer between 1 and 31, both inclusive, representing the day component in the localized value of $arg.
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 following Data Mapper transformation rule: day-from-datetime(“2023-07-27T12:00:00”) will be translated to {day-from-dateTime(xs:dateTime(‘2023-07-27T12:00:00’))} and the return will be 27.
Equal Date
This function states that it will return true or false based on whether the specified Date values are equal.
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:
The $arg1 and $arg2 need to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DD-hh:mm
Sample:
The following Data Mapper transformation rule: is-equal-date(current-date(), current-date()) will be translated to {xs:date(current-date()) = xs:date(current-date())} and the return will be true.
Equal DateTime
This function states that it will return true or false based on whether with the specified DateTime values are equal.
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:
The $arg1 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-equal-datetime(current-dateTime(), current-dateTime()) will be translated to {xs:dateTime(current-dateTime()) = xs:dateTime(current-dateTime())} and the return will be true.
Equal Day
This function states that it will return 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.
Behind the scenes, this function is translated to the following XPath expression: xs:gDay($arg1) = xs:gDay($arg2)
xs:gDay($arg1) = xs:gDay($arg2) as xs:boolean
Rules:
Returns true if the two xs:gDay values (xs:gDay(“—25-14:00”)) have the same starting instant, when considered as days in the same month of the same year.
Sample:
The following Data Mapper transformation rule: is-day-equal(day-from-date(…), day-from-date(…)) will be translated to xs:gDay(day-from-date(xs:date(‘2023-07-27’))) = xs:gDay(day-from-date(xs:date(‘2023-07-27’)))} and the return will be true.
Equal Month
This function states that it will return 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.
Behind the scenes, this function is translated to the following XPath expression: xs:gMonth($arg1) = xs:gMonth($arg2)
xs:gMonth($arg1) = xs:gMonth($arg2) as xs:boolean
Rules:
Returns true if the two xs:gMonth values (xs:gMonth(“–12-14:00”)) have the same starting instant, when considered as months in the same year.
Sample:
The following Data Mapper transformation rule: is-month-equal(current-date(), current-date()) will be translated to {xs:gMonth(current-date()) = xs:gMonth(current-date())} and the return will be true.
Equal MonthDay
This function states that it will return 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.
Behind the scenes, this function is translated to the following XPath expression: xs:gMonthDay($arg1) = xs:gMonthDay($arg2)
xs:gMonthDay($arg1) = xs:gMonthDay($arg2) as xs:boolean
Rules:
Returns true if the two xs:gMonthDay values (xs:gMonthDay(“–12-25-14:00”)) have the same starting instant, when considered as days in the same year.
Sample:
The following Data Mapper transformation rule: is-monthday-equal(current-date(), current-date()) will be translated to {xs:gMonthDay(current-date()) = xs:gMonthDay(current-date())} and the return will be true.
Equal Time
This function states that it will return true or false based on whether the specified Time values are equal.
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 two xs:time values represent the same instant in time, when treated as being times on the same date, before adjusting the timezone.
Sample:
The following Data Mapper transformation rule: is-equal-time(current-time(), current-time()) will be translated to xs:time(current-time()) = xs:time(current-time()) and the return will be true.
Equal Year
This function states that it will return true or false based on whether the specified Year values (xs:gYear) have the same starting time.
Behind the scenes, this function is translated to the following XPath expression: xs:gYear($arg1) = xs:gYear($arg2)
xs:gYear($arg1) = xs:gYear($arg2) as xs:boolean
Rules:
Returns true if the two xs:gYear values (xs:gYear(“2005+12:00”)) have the same starting instant.
Sample:
The following Data Mapper transformation rule: is-year-equal(current-date(), current-date()) will be translated to {xs:gYear(current-date()) = xs:gYear(current-date())} and the return will be true.
Equal YearMonth
This function states that it will return true or false based on whether the specified YearMonth values (xs:gYearMonth) are the same.
Behind the scenes, this function is translated to the following XPath expression: xs:gYearMonth($arg1) = xs:gYearMonth($arg2)
xs:gYearMonth($arg1) = xs:gYearMonth($arg2) as xs:boolean
Rules:
Returns true if the two xs:gYearMonth values (xs:gYearMonth(“1986-02”)) have the same starting instant.
Sample:
The following Data Mapper transformation rule: is-yearmonth-equal(current-date(), current-date()) will be translated to {xs:gYearMonth(current-date()) = xs:gYearMonth(current-date())} and the return will be true.
Stay tuned for the third 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!
Author: Sandro Pereira
Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc.
He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.
View all posts by Sandro Pereira