nœuds / builtin / datatransformation / datetime
Get Time Between Dates
Get the time between two dates
Ce contenu n’est pas encore disponible dans votre langue.
Compare the parts of two dates, such as their years or their days of the month.
What it does
Section titled “What it does”Get Time Between Dates reads Start date and End date and, for each unit you tick in Units, subtracts the start’s value for that part from the end’s value. The results go into one object under Output field name, with one key per unit.
Each unit compares only that part of the two dates, not the total time between them:
| Unit | What it subtracts |
|---|---|
| year | The years. |
| month | The months of the year (0 to 11). |
| week, day | The days of the month (both give the same number). |
| hour, minute, second, millisecond | That part of the clock time. |
For example, from 2026-01-31 to 2026-03-02 gives { year: 0, month: 2, day: -29 }. The values are read in your computer’s local time zone.
When to use it
Section titled “When to use it”- Check whether two dates fall in the same year or month (the result is
0). - Compare clock times on the same day, such as how many hours separate two meetings today.
To get the total elapsed time (for example “how many days until the deadline”), use the recipe in the example below instead.
Inputs and settings
Section titled “Inputs and settings”| Réglage | Type | Ce que cela fait |
|---|---|---|
| Start date (obligatoire) | Date and time | The start date. |
| End date (obligatoire) | Date and time | The end date. |
| Units (obligatoire) | Multiple choice | The units to express the difference in. Larger units are filled first; smaller ones get what remains. Options: year, month, week, day, hour, minute, second, millisecond. |
| Output field name (obligatoire) | Text | The name of the output field. |
| Options | Group | The options for the node. |
| Options › Include input fields | Toggle | Whether to include the input fields in the output. Par défaut : Off |
Both dates accept a picked date or an expression such as {{ $input.dueDate }}. Tick at least one unit.
Outputs
Section titled “Outputs”-
Output
The item holds an object under Output field name, for example { diff: { year: 1, month: -2 } }. Read one value downstream with {{ $input.diff.year }}. A negative number means the end’s part is smaller than the start’s.
Dependencies and credentials
Section titled “Dependencies and credentials”None. This node needs no connection and has no slots for other nodes.
Example workflow
Section titled “Example workflow”Count the whole days until a deadline (total elapsed time):
- Format Date, Date to format
{{ $input.dueDate }}, FormatUnix MS Timestamp, Output field namedueMs, Include input fields on. - Get Current Date then another Format Date with
Unix MS Timestamp, Output field namenowMs, both with Include input fields on. - Math, Operation Subtract, Value
{{ $input.dueMs }}, Second Value{{ $input.nowMs }}, Put Result In FieldmsLeft. - Math, Operation Divide, Value
{{ $input.msLeft }}, Second Value86400000(one day in milliseconds), Put Result In FielddaysLeft. Add a third Math with Operation Round down if you want whole days.
Use Get Time Between Dates itself for same-period checks: Units year and month, then an IF that both are 0 to know two dates are in the same month.
Common issues
Section titled “Common issues”- “day” is negative although the end date is later. The node subtracts days of the month, not total days. From the 31st to the 2nd of a later month gives a negative number. Use the recipe above for elapsed time.
- “week” shows the same number as “day”. Both compare the day of the month. It is not a count of weeks.
- “Invalid duration unit”. A unit in Units is not one of the listed values. Re-select the units from the list.
- The values are
NaN. One of the dates could not be read. Use ISO dates such as2026-03-05.
Related nodes
Section titled “Related nodes”- Extract Part Of A Date: read one part of a single date.
- Format Date: convert dates to timestamps for exact differences.
- Math: subtract and divide timestamps.
- IF: branch on the result.