Logic Apps (Standard) Data Mapper: Date and Time Functions (Part 4)

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top