Manipulating date and time with the datecalc function
Syntax and usage examples for the datecalc function
Overview
You can use the datecalc function to manipulate date and time in a large variety of ways.
Syntax and options
The datecalc function accepts one or two parameters, as follows:
$time_datecalc([dateTime,] offset_expression)
- dateTime
- If date and time are not specified, the current date and time are assumed. This parameter is optional. The supported format is yyyy-mm-dd.
- offset_expression
- The expression represents one or more operations to be applied to date
and time. This parameter is required. You can build an offset expression
by combining one or more of the following parameters:
- + offset_number token
- adds the specified token by the specified offset_number.
- - offset_number token
- subtracts the specified token by the specified offset_number.
- nearest token
- changes the date and time to the nearest token.
- next token
- changes the date and time to the next token.
- previous token
- changes the date and time to the previous token.
where:A token can indicate a day, an amount of time, or a calendar name, as listed below. To indicate a quantity higher than 1, add the "s" at the end of the token:- offset_number
- The number to be applied to the token.
- minute("s")
- The unit of measure to be used in the expression is one or more minutes.
- hour("s")
- The unit of measure to be used in the expression is one or more hours.
- day("s")
- The unit of measure to be used in the expression is one or more days, regardless of whether the day is working or non-working.
- weekday("s")
- The unit of measure to be used in the expression is one or more days of the week, except Saturday and Sunday.
- workday("s")
- The unit of measure to be used in the expression is one or more working days, that is every day of the week except Saturday and Sunday, unless otherwise specified in a non-working days calendar defined for the workflow. You can use the non-working days calendar to manage non-working days which vary over time.
- week("s")
- The unit of measure to be used in the expression is one or more weeks.
- month("s")
- The unit of measure to be used in the expression is one or more months.
- year("s")
- The unit of measure to be used in the expression is one or more years.
- mo, mon, monday
- Use this notation to indicate Monday.
- tu, tue, tuesday
- Use this notation to indicate Tuesday.
- we, wed, wednesday
- Use this notation to indicate Wednesday.
- th, thu, thursday
- Use this notation to indicate Thursday.
- fr, fri, friday
- Use this notation to indicate Friday.
- sa, sat, saturday
- Use this notation to indicate Saturday.
- su, sun, sunday
- Use this notation to indicate Sunday.
Examples
Use the following expression to add one day to the current date
(2022-04-01):
$time_datecalc('+1 day')
The result is similar
to the following:2022-04-02T16:30:00+02:00[Europe/Rome]
Use the following expression to calculate the last day of the month starting from
2022-04-01:
$time_datecalc('2022-04-01','next monthend')
The
result is similar to the
following:2022-04-30T16:30:10.123+02:00[Europe/Rome]
Use the following expression to calculate the next Monday starting from today
(2022-04-01) and add one day to the
result:
$time_datecalc('+ nearest mo +1 day')
The result is
similar to the
following:2022-04-05T00:00:00+02:00[Europe/Rome]
Use the following expression to add 30 working days to
2022-04-01:
$time_datecalc('2022-04-01T16:30:00','+30 workdays')
The
result is similar to the
following:2022-05-13T16:30:00+02:00[Europe/Rome]
Use the following expression to calculate the last day of the month starting from
2022-04-01 and express it in the local
date:
$time_datecalc('next monthend').$time_localDate()
The
result is similar to the
following:4/30/2022
For more information about other functions provided with HCL Universal Orchestrator, see Proprietary functions for JSONata.