Date and time package guide
Use Date and time actions to parse, calculate, format, and compare dates with stored UTC offsets.
Version 2.17.1. Installed versions can differ. Examples are illustrative and not tested. See Packages.
Prerequisites
Nothing to install, and no session.
- A date keeps its offset from UTC, like
+02:00, not a time zone name. Daylight saving is not applied. - Compare actions and differences use the real moment, so
10:00+00:00equals11:00+01:00. Calendar fields (day, month, hour) use the date and time as stored, at its offset. - Years 1 to 9999 only. A step that moves a date outside this range fails.
- Month and day names, and AM/PM, are in English.
Custom patterns (Assign and To string) use these letters:
| Write | Means |
|---|---|
yyyy MM dd | year, month, day (u also means year) |
HH / hh | hour 0-23 / 1-12 |
mm ss | minutes, seconds |
SSS | parts of a second, up to 7 digits (n too) |
a | AM or PM |
EEE / EEEE | Mon / Monday (1 to 3 E give the short name) |
X (or x, Z) | offset, like +00:00 |
'T' | the letter T as is |
Other characters are used as they are. Not all Java pattern letters work.
The named formats below show To string for 2011-12-03T10:15:30+00:00. Time-only formats work only in To string. In Assign, a date-only value without an offset gives midnight UTC.
| Named format | To string output | Assign input forms |
|---|---|---|
BASIC_ | 20111203+00:00 | yyyy with or without +HH:mm offset. |
ISO_ | 2011-12-03 | yyyy-MM-dd. |
ISO_ | 2011-12-03+00:00 | yyyy-MM-dd plus +HH:mm offset. |
ISO_ | 2011-12-03+00:00 | Same date with or without +HH:mm offset. |
ISO_ | 10:15:30 | Not an Assign choice. |
ISO_ | 10:15:30+00:00 | Not an Assign choice. |
ISO_ | 10:15:30+00:00 | Not an Assign choice. |
ISO_ | 2011-12-03 | yyyy-MM-dd'T'HH:mm:ss, with optional .fff, or minute precision yyyy-MM-dd'T'HH:mm. No offset. |
ISO_ | 2011-12-03 | Seconds plus +HH:mm, optional .fff before offset; also seconds without offset. |
ISO_ | 2011-12-03 | Same as ISO_; no bracketed zone ID. |
ISO_ | 2011-12-03 | Same as ISO_. |
ISO_ | 2011-337 | Year and day-of-year, for example 2011-337; UTC midnight. |
ISO_ | 2011-W48-6 | ISO week year, week, weekday Monday=1 through Sunday=7; UTC midnight. |
ISO_ | 2011-12-03 | Seconds with literal Z, with optional .fff before Z; UTC. |
RFC_ | Sat, 03 Dec 2011 10:15:30 GMT | RFC 1123 text in English with GMT; UTC. |
ISO_INSTANT and RFC_1123_DATE_TIME change the time to UTC. The others keep the stored time; the local forms leave out the offset. Named outputs show no parts of a second. Named time zones are not supported.
Shared fields
- Empty fields use the default. Give required fields a value. Choices ignore upper or lower case. A field for another mode is ignored, but it must still hold a valid value.
- Actions do not change the input: put the result in a variable (the same one, to replace it).
- Every Datetime input defaults to
0001-01-01T00:00:00+00:00(year 1). Always set it.
Datetime input: a Datetime variable such as $when$, or a date written like 2024-03-15T10:30:00+00:00. Without an offset, UTC is used. Write the offset to avoid surprises. Convert a String variable with Assign first.
Add/Subtract: a negative val goes the other way. MILLIS is milliseconds and WEEKS is 7 days. MILLIS through WEEKS can take parts, like 1.5. MONTHS and YEARS use whole numbers only (1.5 becomes 1) and follow the calendar. If the day does not exist, you get the last day of the month: Jan 31 + 1 month = Feb 29 in 2024. The offset stays the same.
First/Last day of month/year: the time and offset stay; the time is not set to midnight. A date already on that day does not change. Leap years count.
Next/Previous weekday: daysOfWeek takes MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY or SUNDAY. includeInputIfMatch=true: if the date is already that weekday, keep it. false: always move, so a Friday goes to the next or previous Friday. The time and offset stay.
Next/Previous working date: working days are Monday to Friday, minus the dates in holidayDates. The input date itself never counts. Give a List of date texts or Datetime items, such as 2024-03-18T00:00:00+00:00. Only the calendar date is compared. Empty or bad entries are skipped. There is no built-in holiday list. The time and offset stay.
These rows are the same in many actions. Each action's Inputs part says which it uses.
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
source | Source date and time variable | Datetimedefault 0001-01-01T00:00:00+00:00optional | The date to use. See Datetime input. |
other | Date and time variable to be compared to | Datetimedefault 0001-01-01T00:00:00+00:00optional | The date to compare with. See Datetime input. |
input | Input datetime | Datetimedefault 0001-01-01T00:00:00+00:00optional | The date to move. See Datetime input. |
input | Enter datetime value | Datetimedefault 0001-01-01T00:00:00+00:00optional | The date to start from. See Datetime input. |
days | Select day | Weekdefault MONDAYoptional | The weekday. See Next/Previous weekday. |
include | Include same day if it matches | Booleandefault falseoptional | See Next/Previous weekday. |
holiday | List of holiday dates | Listdefault []optional | The holidays. See Next/Previous working date. |
Actions
Add (datetimeAdd)
Add time to a date. See Add/Subtract.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
val | Time value to add | Numberdefault 0optional | The amount. |
unit | Time unit to add | Unitdefault DAYSoptional | MILLIS, SECONDS, MINUTES, HOURS, DAYS, WEEKS, MONTHS or YEARS. |
Also uses the shared fields: source.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The new date. |
Example
Set source=2024-01-31T00:00:00+00:00, val=1, unit=MONTHS. Put result in $shifted$.
Expected result
$shifted$ is 2024-02-29T00:00:00+00:00.
Assign (datetimeAssign)
Read a date from text with a named or custom pattern, or copy a Datetime.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
option | Select the source datetime variable/ value | Optiondefault constantoptional | constant: read the text in source. variable: copy date; the format fields are ignored. |
source | Enter the date time | Stringdefault ""optional | With constant: text that matches the format, such as 2011-12-03 for ISO_. |
format | Select date time format | Formatdefault preoptional | With constant: pre uses pre, custom uses custom. |
pre | preBuiltFormat | Predefault ISO_optional | With constant and pre: a named format from the Prerequisites table. |
custom | customFormat | Stringdefault ""optional | With constant and custom: a pattern, for example dd/. See the pattern letters in Prerequisites. |
date | Select the source date time variable | Datetimedefault 0001-01-01T00:00:00+00:00optional | With option= only: a Datetime variable or a date with offset. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The date and offset. |
Example
Set option=constant, source=03/12/2011 10:15:30.250, formatType=custom, customFormat=dd/MM/yyyy HH:mm:ss.SSS. Put result in $when$.
Expected result
$when$ is 2011-12-03T10:15:30.250+00:00. With source=2011-12-03, formatType=preBuilt and preBuiltFormat=ISO_LOCAL_DATE, it is midnight UTC. Text that does not match the pattern fails.
Calculate Datetime Duration (datetimeCalculateDuration)
Get the time between two dates as text. Hours can be more than 24.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
start | Start datetime | Datetimedefault 0001-01-01T00:00:00+00:00optional | Datetime input. |
end | End datetime | Datetimedefault 0001-01-01T00:00:00+00:00optional | Datetime input. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | String | The duration, such as PT26: all hours, then minutes and seconds. Zero is PT0. |
Example
Set startDate=2024-03-15T10:00:00+00:00, endDate=2024-03-16T12:03:04+00:00. Put result in $duration$.
Expected result
$duration$ is PT26H3M4S. The same moment gives PT0S. An earlier end gives minus values, for example PT-1H. Parts of a second use a period and up to 9 digits.
Difference between dates (datetimeDifferenceBetweenDates)
Count whole units from source to target. An earlier target gives a negative number.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
source | Source Date and time Variable | Datetimedefault 0001-01-01T00:00:00+00:00optional | Datetime input. |
target | Date and time variable to be compared | Datetimedefault 0001-01-01T00:00:00+00:00optional | Datetime input. |
unit | Time unit | Diffdefault DAYSoptional | Counts whole units only. MONTHS and YEARS follow the calendar (a year is 12 whole months). WEEKS is 7 days. DAYS, HOURS, MINUTES and SECONDS use the elapsed time. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | The number of whole units. |
Example
Set source=2024-01-01T00:00:00+00:00, target=2024-03-01T00:00:00+00:00, unit=MONTHS. Put result in $difference$.
Expected result
$difference$ is 2. The same dates the other way with unit=DAYS give -60. Less than one unit gives 0. Months count from the source date and its time of day.
First day of month (datetimeFirstDayOfMonth)
Move to the first day of the month. See First/Last day.
Inputs
Uses the shared fields: inputDate (Input datetime).
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The first day of the month. |
Example
Set inputDate=2024-03-15T10:30:00+00:00. Put result in $edge$.
Expected result
$edge$ is 2024-03-01T10:30:00+00:00.
First day of year (datetimeFirstDayOfYear)
Move to the first day of the year. See First/Last day.
Inputs
Uses the shared fields: inputDate (Input datetime).
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The first day of the year. |
Example
Set inputDate=2024-03-15T10:30:00+00:00. Put result in $edge$.
Expected result
$edge$ is 2024-01-01T10:30:00+00:00.
Get (datetimeGet)
Get one part of a date, such as the day or hour, at its offset.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
source | Date time variable to get the selected value | Datetimedefault 0001-01-01T00:00:00+00:00optional | Datetime input. |
get | Datetime value to get | Getdefault DAYOFMONTHoptional | DAYOFMONTH is 1..31; DAYOFWEEK is Monday=1 through Sunday=7; DAYOFYEAR is 1..365/366. LENGTHOFMONTH is 28..31; LENGTHOFYEAR is 365 or 366. HOUR is 0..23; MINUTE and SECOND are 0..59; MONTH is 1..12; YEAR is the calendar year. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | The part you chose. |
Example
Set source=2024-02-29T13:45:07+00:00, getOptions=DAYOFWEEK. Put result in $weekday$.
Expected result
$weekday$ is 4 (Thursday). DAYOFYEAR gives 60, and LENGTHOFYEAR gives 366.
Is after (datetimeIsAfter)
Check if source is later than other, with offsets taken into account.
Inputs
Uses the shared fields: source, other.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Boolean | true if source is later; otherwise false. |
Example
Set source=2024-01-02T00:00:00+00:00, other=2011-12-03T10:15:30+00:00. Put result in $matches$.
Expected result
$matches$ is true. The same moment gives false, also with a different offset.
Is before (datetimeIsBefore)
Check if source is earlier than other, with offsets taken into account.
Inputs
Uses the shared fields: source, other.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Boolean | true if source is earlier; otherwise false. |
Example
Set source=2024-01-02T00:00:00+00:00, other=2011-12-03T10:15:30+00:00. Put result in $matches$.
Expected result
$matches$ is false. The same moment gives false, also with a different offset.
Is equal (datetimeIsEqual)
Check if two dates are the same moment. The offsets can differ.
Inputs
Uses the shared fields: source, other.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Boolean | true for the same moment; otherwise false. |
Example
Set source=2011-12-03T10:15:30+00:00, other=2011-12-03T11:15:30+01:00. Put result in $same$.
Expected result
$same$ is true. The same clock time with another offset is a different moment, so it gives false.
Is leap year (datetimeIsLeapYear)
Check if the year of the date is a leap year.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
source | Date and time variable to check | Datetimedefault 0001-01-01T00:00:00+00:00optional | Datetime input. |
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Boolean | true for a leap year, using the year at the stored offset. |
Example
Set source=2024-02-29T00:00:00+00:00. Put result in $leap$.
Expected result
$leap$ is true. A date in 2023 gives false. Years divisible by 100 are not leap years unless divisible by 400.
Last day of month (datetimeLastDayOfMonth)
Move to the last day of the month. See First/Last day.
Inputs
Uses the shared fields: inputDate (Input datetime).
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The last day of the month. |
Example
Set inputDate=2024-03-15T10:30:00+00:00. Put result in $edge$.
Expected result
$edge$ is 2024-03-31T10:30:00+00:00.
Last day of year (datetimeLastDayOfYear)
Move to the last day of the year. See First/Last day.
Inputs
Uses the shared fields: inputDate (Input datetime).
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The last day of the year. |
Example
Set inputDate=2024-03-15T10:30:00+00:00. Put result in $edge$.
Expected result
$edge$ is 2024-12-31T10:30:00+00:00.
Get Next Day Of Week (datetimeNextDayOfWeek)
Find the next date on a weekday. See Next/Previous weekday.
Inputs
Uses the shared fields: inputDate (Enter datetime value), daysOfWeek, includeInputIfMatch.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The date on that weekday. |
Example
Set inputDate=2024-03-15T00:00:00+00:00, daysOfWeek=FRIDAY, includeInputIfMatch=false. Put result in $weekday$.
Expected result
$weekday$ is 2024-03-22T00:00:00+00:00. With includeInputIfMatch=true, it stays 2024-03-15T00:00:00+00:00.
Get Next Working Date (datetimeNextWorkingDate)
Find the next working date. See Next/Previous working date.
Inputs
Uses the shared fields: inputDate (Enter datetime value), holidayDates.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The next working date, with the same time and offset. |
Example
Create $holidays$ as a List with one String item 2024-03-18T00:00:00+00:00. Set inputDate=2024-03-15T00:00:00+00:00, holidayDates=$holidays$. Put result in $working$.
Expected result
$working$ is 2024-03-19T00:00:00+00:00: it skips the weekend and the Monday holiday. With no holidays, it is March 18.
Get Previous Day Of Week (datetimePreviousDayOfWeek)
Find the previous date on a weekday. See Next/Previous weekday.
Inputs
Uses the shared fields: inputDate (Enter datetime value), daysOfWeek, includeInputIfMatch.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The date on that weekday. |
Example
Set inputDate=2024-03-15T00:00:00+00:00, daysOfWeek=MONDAY, includeInputIfMatch=false. Put result in $weekday$.
Expected result
$weekday$ is 2024-03-11T00:00:00+00:00. With daysOfWeek=FRIDAY and includeInputIfMatch=true, it stays 2024-03-15T00:00:00+00:00.
Get Previous Working Date (datetimePreviousWorkingDate)
Find the previous working date. See Next/Previous working date.
Inputs
Uses the shared fields: inputDate (Enter datetime value), holidayDates.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The previous working date, with the same time and offset. |
Example
Set inputDate=2024-03-18T00:00:00+00:00 and leave holidayDates empty. Put result in $working$.
Expected result
$working$ is 2024-03-15T00:00:00+00:00, the Friday before. A holiday on March 15 moves it to March 14.
Subtract (datetimeSubtract)
Take time away from a date. See Add/Subtract.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
val | Time value to subtract | Numberdefault 0optional | The amount. |
unit | Time unit to subtract | Unitdefault DAYSoptional | MILLIS, SECONDS, MINUTES, HOURS, DAYS, WEEKS, MONTHS or YEARS. |
Also uses the shared fields: source.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Datetime | The new date. |
Example
Set source=2024-03-10T06:00:00+00:00, val=36, unit=HOURS. Put result in $shifted$.
Expected result
$shifted$ is 2024-03-08T18:00:00+00:00.
Convert Datetime To Epoch (datetimeToEpoch)
Change a date to Unix epoch seconds (seconds since 1 Jan 1970 UTC), not milliseconds.
Inputs
Uses the shared fields: inputDate (Enter datetime value).
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | Number | Whole seconds since 1970-01-01. |
Example
Set inputDate=1970-01-01T00:01:00+00:00. Put result in $epoch$.
Expected result
$epoch$ is Number 60. The same moment with another offset gives the same number. Parts of a second are dropped (rounded down). Dates before 1970 give negative numbers.
To string (datetimeToString)
Write a date as text with a named or custom pattern.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
select | Select date time format | Selectdefault PREBUILToptional | PREBUILT uses pre; CUSTOM uses pattern. |
pre | preBuiltPattern | Predefault ISO_optional | With PREBUILT: a named format from the Prerequisites table. |
pattern | patternInput | Stringdefault ""optional | With CUSTOM: a pattern, for example yyyy/. It uses the stored offset. |
Also uses the shared fields: source.
Outputs
| Identifier | Type | Meaning |
|---|---|---|
result | String | The date as text. |
Example
Set source=2011-12-03T10:15:30+00:00, selectPattern=CUSTOM, patternInput=yyyy/MM/dd HH:mm:ss.SSS a. Put result in $text$.
Expected result
$text$ is 2011/12/03 10:15:30.000 AM. PREBUILT with ISO_LOCAL_DATE_TIME gives 2011-12-03T10:15:30. A custom pattern shows the parts of a second you ask for. A bad pattern can fail.
Conditions
Date condition (datetimeCondition)
Compare two dates in an If or Loop. Offsets are taken into account.
Inputs
| Identifier | Editor field | Type; required; default | Use |
|---|---|---|---|
source | Source value | Datetimedefault 0001-01-01T00:00:00+00:00required | Datetime input. |
operator | Operator | Operatordefault EQoptional | Choose EQ (=), NEQ (≠), GT (>), GTE (≥), LT (<), or LTE (≤). |
target | Target value | Datetimedefault 0001-01-01T00:00:00+00:00required | Datetime input. |
Outputs
None. The condition is true for a match, otherwise false.
Example
On an If step, set source=2011-12-03T10:15:30+00:00, operator=LT, target=2011-12-25T00:00:00+00:00.
Expected result
The condition is true. GT gives false. The same moment is equal across different offsets. Read text that is not ISO with Assign first.