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).
Add days
This function states that it will add a positive or negative number of days to the specified timestamp. Returns a timestamp that’s respectively later or earlier than the specified timestamp.
To be documented in the future.
Add DayTime to Date
This function states that it will add 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.
Behind the scenes, this function is translated to the following XPath function: xs:date(xs:date($arg1) + xs:dayTimeDuration($arg2))
- The expression xs:date(xs:date($arg1) + xs:dayTimeDuration($arg2)) returns
xs:date
Rules:
- The
$arg
1 needs to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ. - The
$arg
2 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]M[n]DT[n]H[n]M[n]S, where n is a number.- The letters mean the representation of date and time:
- P express that this is a period format and should be the first character;
- Y for years; M for months; D for days;
- T is the delimiter for the time;
- H for hours; M for minutes; S for seconds;
- Therefore PT means Period of Time.
- PT20S: parses as 20 seconds.
- PT15M: parses as 15 minutes (where a minute is 60 seconds).
- PT10H: parses as 10 hours (where an hour is 3600 seconds).
- P2D: parses as 2 days (where a day is 24 hours or 86400 seconds).
- P2DT3H4M: parses as 2 days, 3 hours, and 4 minutes.
- The letters mean the representation of date and time:
Sample:
- The following Data Mapper transformation rule: add-daytime-to-date(“2023-07-25”, “P2D”) will be translated to {xs:date(xs:date(‘2023-07-25’) + xs:dayTimeDuration(‘P2D’))} and the return will be 2023-07-27
Add DayTime to DateTime
This function states that it will add 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.
Behind the scenes, this function is translated to the following XPath function: xs:dateTime(xs:dateTime($arg1) + xs:dayTimeDuration($arg1))
The expression xs:dateTime(xs:dateTime($arg1) + xs:dayTimeDuration($arg1)) returns
Timexs:date
Rules:
- 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. - The
$arg
2 needs to be an interval in 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.- The letters mean the representation of date and time:
- P express that this is a period format and should be the first character;
- Y for years; M for months; D for days;
- T is the delimiter for the time;
- H for hours; M for minutes; S for seconds;
- Therefore PT means Period of Time.
- PT20S: parses as 20 seconds.
- PT15M: parses as 15 minutes (where a minute is 60 seconds).
- PT10H: parses as 10 hours (where an hour is 3600 seconds).
- P2D: parses as 2 days (where a day is 24 hours or 86400 seconds).
- P2DT3H4M: parses as 2 days, 3 hours, and 4 minutes.
- The letters mean the representation of date and time:
Sample:
- The following Data Mapper transformation rule: add-daytime-to-datetime(“2023-07-25T12:00:00”, “PT20S”) will be translated to {xs:dateTime(xs:dateTime(‘2023-07-25T12:00:00’) + xs:dayTimeDuration(‘PT20S’))} and the return will be 2023-07-25T12:00:20
Add DayTime to Time
This function states that it will add 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 at an earlier Time.
Behind the scenes, this function is translated to the following XPath function: xs:time(xs:time($arg1) + xs:dayTimeDuration($arg2))
xs:time(xs:time($arg1) + xs:dayTimeDuration($arg2)) returns xs:timeThe expression
Rules:
- The
$arg
1 needs to be an xs:time in the following format HH:mm:ss or HH:mm:ss-hh:mm. - The
$arg
2 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- The letters mean the representation of date and time:
- P express that this is a period format and should be the first character;
- Y for years; M for months; D for days;
- T is the delimiter for the time;
- H for hours; M for minutes; S for seconds;
- Therefore PT means Period of Time.
- PT20S: parses as 20 seconds.
- PT15M: parses as 15 minutes (where a minute is 60 seconds).
- PT10H: parses as 10 hours (where an hour is 3600 seconds).
- P2D: parses as 2 days (where a day is 24 hours or 86400 seconds).
- P2DT3H4M: parses as 2 days, 3 hours, and 4 minutes.
- The letters mean the representation of date and time:
Sample:
- The following Data Mapper transformation rule: add-daytime-to-time(“11:12:00”, “PT1M”) will be translated to {xs:time(xs:time(’11:12:00′) + xs:dayTimeDuration(‘PT1M’))} and the return will be 11:13:00
Add YearMonth to DateTime
This function states that it will Add 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.
Behind the scenes, this function is translated to the following XPath function: xs:date(xs:date($arg1) + xs:yearMonthDuration($arg2))
- The expression xs:date(xs:date($arg1) + xs:yearMonthDuration($arg2)) returns
xs:date
Rules:
- The
$arg
1 needs to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ. - The
$arg
2 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]M, where n is a number.- The letters mean the representation of date and time:
- P express that this is a period format and should be the first character;
- Y for years; M for months;
- Therefore PT means Period of Time.
- PT1Y: parses as 1 Year.
- P1M: parses as 1 Month.
- The letters mean the representation of date and time:
Sample:
- The following Data Mapper transformation rule: add-yearmonth-to-date(“2023-07-26Z”, “P1M”) will be translated to {xs:date(xs:date(‘2023-07-26Z’) + xs:yearMonthDuration(‘P1M’))} and the return will be 2023-08-26Z.
Adjust Date
This function states that it will adjust the specified Date value (xs:date) to the current or dynamic time zone, or to no timezone at all; the result is the date in the target timezone that contains the starting instant of the supplied date.
Behind the scenes, this function is translated to the following XPath function: adjust-date-to-timezone
(xs:date($arg))
fn:adjust-date-to-timezone
($arg as xs:date?
)as xs:date?
Rules:
- The
$arg
needs to be an xs:date in the following format yyyy-MM-DD or yyyy-MM-DDZ.
Sample:
- The expression
fn:adjust-date-to-timezone(xs:date("2002-03-07"))
returnsxs:date("2002-03-07-05:00")
.
Adjust DateTime
This function states that it will adjust the specified DateTime value (xs:dateTime) to the current or dynamic time zone, or to no timezone at all.
Behind the scenes, this function is translated to the following XPath function: adjust-dateTime-to-timezone(xs:dateTime($arg))
fn:adjust-dateTime-to-timezone
($arg as xs:dateTime?
)as xs:dateTime?
Rules:
- 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:adjust-dateTime-to-timezone(xs:dateTime(‘2002-03-07T10:00:00-07:00’)) returns xs:dateTime(‘2002-03-07T12:00:00-05:00’).
Adjust Time
This function states that it will adjust the specified Time value (xs:time) to the current or dynamic time zone, or to no timezone at all.
Behind the scenes, this function is translated to the following XPath function: adjust-time-to-timezone(xs:time($arg))
fn:adjust-time-to-timezone
($arg as xs:time?
)as xs:time?
Rules:
- 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:adjust-time-to-timezone(xs:time(“10:00:00”)) returns xs:time(“10:00:00-05:00”).
Current date
This function states that it will return the current date in YYYY-MM-DD format. It depends on the implicit timezone (in many cases, if not all, it will include the offset).
Behind the scenes, this function is translated to the following XPath function: current-date()
fn:current-date
()as xs:date
Rules:
- Returns
xs:date(fn:current-dateTime())
. This is anxs:date
(with timezone) that is current at some time during the evaluation of a query or transformation in whichfn:current-date
is executed. - The returned date will always have an associated timezone, which will always be the same as the implicit timezone in the dynamic context.
Sample:
- For example, a call of
fn:current-date()
might return2023-07-21+01:00
.
Current DateTime value
This function states that it will return the current date and time in YYYY-MM-DDThh:mm:ss format.
Behind the scenes, this function is translated to the following XPath function: current-dateTime()
fn:current-dateTime
()as xs:dateTimeStamp
Rules:
- Returns the current dateTime (with timezone) from the dynamic context. This is an
xs:dateTime
that is current at some time during the evaluation of a query or transformation in whichfn:current-dateTime
is executed.
Sample:
- For example, a call of
fn:current-dateTime()
might return 2023-07-26T23:43:42.392+01:00.
Current time
This function states that it will return the current date and time in YYYY-MM-DDThh:mm:ss format. It depends on the implicit timezone (in many cases, if not all, it will include the offset – 23:19:30.985+01:00).
Behind the scenes, this function is translated to the following XPath function: current-time()
fn:current-time
()as xs:time
Rules:
- Returns
xs:time(fn:current-dateTime())
. This is anxs:time
(with timezone) that is current at some time during the evaluation of a query or transformation in whichfn:current-time
is executed. - The returned time will always have an associated timezone, which will always be the same as the implicit timezone in the dynamic context.
Sample:
- For example, a call of
fn:current-time()
might return23:19:30.985+01:00
.
Stay tune for the second 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!