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).