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

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 DayTime: Duration 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).

Time zone from Date

This function states that it will return the time zone from the specified Date value (xs:date).

Behind the scenes, this function is translated to the following XPath function: timezone-from-date($arg)

  • fn:timezone-from-date($arg as xs:date?) as xs:dayTimeDuration?

Rules:

  • The function returns the timezone component of $arg, if any. If $arg has a timezone component, then the result is an xs:dayTimeDuration that indicates deviation from UTC; its value may range from +14:00 to -14:00 hours, both inclusive. If $arg has no timezone component, the result is the empty sequence.
  • The $arg1 needs to be an xs:date in the following format yyyy-MM-DD-hh:mm or yyyy-MM-DDZ.

Sample:

  • The expression fn:timezone-from-date(xs:date("2023-07-29-05:00")) returns xs:dayTimeDuration("-PT5H").
  • The expression fn:timezone-from-date(xs:date("2023-07-29Z")) returns xs:dayTimeDuration("PT0S").
  • The expression fn:timezone-from-date(xs:date("2023-07-29")) returns ().

Time zone from DateTime

This function states that it will return the time zone from the specified DateTime value (xs:dateTime).

Behind the scenes, this function is translated to the following XPath function: timezone-from-dateTime($arg)

  • fn:timezone-from-dateTime($arg as xs:dateTime?) as xs:dayTimeDuration?

Rules:

  • The function returns the timezone component of $arg, if any. If $arg has a timezone component, the result indicates deviation from UTC; its value may range from +14:00 to -14:00 hours, both inclusive. If $arg has no timezone component, the result is an empty sequence.
  • The $arg1 needs to be an xs:dateTime in the following format yyyy-MM-DDTHH:mm:ssZ or yyyy-MM-DDTHH:mm:ss-hh:mm.

Sample:

  • The expression fn:timezone-from-dateTime(xs:dateTime("2023-07-29T13:20:00-05:00")) returns xs:dayTimeDuration("-PT5H").
  • The expression fn:timezone-from-dateTime(xs:dateTime("2023-07-29T13:20:00Z")) returns xs:dayTimeDuration("PT0S").
  • The expression fn:timezone-from-dateTime(xs:dateTime("2023-07-29T00:00:00")) returns ().

Time zone from Time

This function states that it will return the time zone from the specified Time value (xs:time).

Behind the scenes, this function is translated to the following XPath function: timezone-from-time($arg)

  • fn:timezone-from-time($arg as xs:time?) as xs:dayTimeDuration?

Rules:

  • The function returns the timezone component of $arg, if any. If $arg it has a timezone component, the result indicates deviation from UTC; its value may range from +14:00 to -14:00 hours, both inclusive. If $arg has no timezone component, the result is an empty sequence.
  • The $arg needs to be an xs:time in the following format HH:mm:ssZ or HH:mm:ss-hh:mm.

Sample:

  • The expression fn:timezone-from-time(xs:time("13:20:00-05:00")) returns xs:dayTimeDuration("-PT5H").
  • The expression fn:timezone-from-time(xs:time("13:20:00Z")) returns xs:dayTimeDuration("PT0S").
  • The expression fn:timezone-from-time(xs:time("13:20:00")) returns ().

Year from Date

This function states that it will return the year from the specified Date value (xs:date).

Behind the scenes, this function is translated to the following XPath function: year-from-date($arg)

  • fn:year-from-date($arg as xs:date?) as xs:integer?

Rules:

  • The function returns an xs:integer representing the year in the local value of $arg. The value may be negative.
  • The $arg needs to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ.

Sample:

  • The expression fn:year-from-date(xs:date("2023-07-29")) returns 2023.
  • The expression fn:year-from-date(xs:date("2023-07-29+05:00")) returns 2023.
  • The expression fn:year-from-date(xs:date("-0002-06-01")) returns -2

Year from DateTime

This function states that it will return the year from the specified DateTime value (xs:dateTime).

Behind the scenes, this function is translated to the following XPath function: year-from-dateTime($arg)

  • fn:year-from-dateTime($arg as xs:dateTime?) as xs:integer?

Rules:

  • The function returns an xs:integer representing the year in the local value of $arg. The value may be negative.
  • 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:year-from-dateTime(xs:dateTime("2023-07-29T21:30:00-05:00")) returns 2023.
  • The expression fn:year-from-dateTime(xs:dateTime("2023-07-29T19:20:00")) returns 2023.
  • The expression fn:year-from-dateTime(xs:dateTime("2021-12-31T24:00:00")) returns 2022.
  • The expression fn:year-from-dateTime(xs:dateTime("-0002-06-06T00:00:00")) returns -2

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