Date & Time Operations

Date & Time Operations

Handling dates and times in XPath is essential for printing timestamps, performing date arithmetic, formatting output, and conditioning elements based on time-based rules.

This section covers these functions in depth.

Printing the current date/time (current-date())

Add or subtract a number of days, months or years to/from a date

Formatting a date/time

Conditioning an element based on the current date

Printing the current date/time (current-date())


If you want to insert the current date (timestamp) e.g. as a text, then you can use the xpath function, current-date() and current-dateTime() like so:

   

 

This outputs the date (and time if selected) in this format:


  NG2CurrentDateTime0002

(Year, month, date, hour and timezone)

 


Add or subtract a number of hours, days, months or years to/from a date or timestamp

You can use the standard Xpath 2.0 function, xs:dayTimeDuration(), if you want to add or subtract a number of days to/from a valid date.

You can e.g. use this function to add 5 days to the current date with this Xpath expression: 
current-date() + xs:dayTimeDuration('P5D')

The format of the xs:dayTimeDuration('P5D') is:
  • P indicates a period indicator.

  • 5 (an integer) is the number of days to add or subtract.

  • D is indicates that it is a number of days.


If you want to subtract a number of days, then you can proceed the duration with a minus like so:
xs:dayTimeDuration('-P5D')

You can also add/subtract a number of years and months with the function:
xs:yearMonthDuration('P1Y2M')
It follows a similar structure for the format:
  • P indicates a period.

  • 1 (an integer) is the number of years to add/subtract.

  • Y indicates that the previous integer is a number of years.

  • 2 (integer) is the number of months to add/subtract.

  • M indicates, that the previous integer is a number of months.

Example
If you have a date in a string with which you want to add or subtract a time period, then you first need to convert the date into the format: 'YYYY-MM-dd', where YYYY is the year (4 digits), MM is the month (2 digits) and dd is the date of the month (2 digits).

If e.g. you want to add 30 days to July 4th 2025, then you need to e.g. use substring and concat to build this string: '2025-07-04'. Then you need to convert this string into a date with the function, xs:date() and then add the 30 days like so:
xs:date('2025-07-04') + xs:dayTimeDuration('P30D')
This expression returns the date: 2025-08-03.

You can use the same technique to add hours to a time stamp.

You can see the format of a timestamp as the output of this xpath function:
current-dateTime()

This in this format:
2025-05-13T12:12:47.8408131+02:00
(yyyy-mm-ddTtime+offset)

You can also set the timestamp without the offset like in this format:
2025-03-13T06:05:33

If you now e.g. want to add 2 hours to this timestamp, then you can do it like below:

xs:dateTime('2025-03-13T06:05:33') + xs:dayTimeDuration('PT20H')

The expression above adds 20 hours to the timestamp and outputs this:
2025-03-14T02:05:33
(Notice that the date is the next day).



Formatting a date/time


You can however reformat the date (and time)  with the ng:dateTimeFormat and ng:dateFormat functions.

If you want to change the formatting or only use a part of it, you can e.g. move the result into a variable and e.g. use a part via substring.

Conditioning an element based on the current date
One way to use the current-date() XPath function is to condition elements in the designer by comparing the current date with an interval of date. This can e.g. be used for including a christmas greeting in the designer.

 

  NG2CurrentDateCondition0001


The setup consists of 3 parts:
  1. A definition of a variable, that we in this example name: Currentdate.
    In line 1 this expression is used in order to extract the current date and to format it in the format year,month and day of the month with no delimiters. If we start from the inside the function, current-date() returns the current date in the format: year-month-day of the month+timezone. This date is converted into a string with the string() function. The result of the string function is used as an argument in the substring function, which here extracts the first 10 characters from the current-date() function, which means that the reference to the timezone is removed. The ng:dateFormat function finally removes the '-' between the year, month and day (this could also have been achieved with the translate xpath function). Now the Currentdate variable contains the year month and day without any delimiters.

  2. In the second line we compare the Currentdate variable with two fixed dates, so that the christmas greeting is only included in the output in the range from December 1st to December 24th.

  3. Finally in the third line we print out the text 'Merry christmas' - but only i the condition above is true.
 

    • Related Articles

    • Numeric Operations & Comparisons

      XPath supports various mathematical and logical operations. This section explains how to perform calculations, round numbers, compare values, and use Boolean logic in XPath expressions Solving the error: Unsuitable types for + operation (xs:string, ...
    • Payload to time-limited store

      The Advanced, other workflow component, Payload to time-limited store is related to the tenant setting, Time-limited persistent storage. With this component you can temporarily store the current payload into a time-limited storage, that you have ...
    • Delete from time-limited store

      The Advanced, other workflow component, Delete from time-limited store is related to the tenant setting, Time-limited persistent storage. With this component you can delete a document from the time-limited store, that you have previously saved into ...
    • Time-limited store to payload

      The Advanced, other workflow component, Time-limited store to payload is related to the tenant setting, Time-limited persistent storage. With this component you can load a stored document from a time-limited store into the current payload. Related ...
    • Time-limited persistent storage in workflows

      Introduction Some customers are using the file system or the library to store input XML documents, in case they need to be re-processed later due to an error. Other customers use the file system or the library to temporarily store inputs that need to ...