# Date & Time

> Manipulates date and time values, offering formatting, calculations, and current time generation.

Source: https://docs.sommatic.ai/en/nodes/data.datetime/

- Slug: `data.datetime`
- Family: Data
- Version: 1.0.0
- Status: Available
- Execution: sync

Manipulates date and time values, offering formatting, calculations, and current time generation.

This utility does not rely on external services and uses the 'luxon' library for robust handling of timezones and formats.

**Operations:**
- **Now:** Returns the current date/time in the specified timezone.
- **Format:** Converts a date string into a specific format pattern.
- **Add:** Adds time (minutes, days, etc.) to a given date.
- **Diff:** Calculates the difference between two dates in a specific unit.

**Use Cases:**
- Generating timestamps for DB records.
- Calculating "Due Date" (Now + 7 Days).
- Formatting dates for email templates (e.g., "Jan 01, 2024").

## Configuration

- `operation` (string, required): The date operation to perform. Default: `now`. Allowed values: `now`, `format`, `add`, `diff`.
- `value` (string, optional, accepts expressions): The source date (ISO string). Required for Format, Add, and Diff. Shown when: operation = `format` | `add` | `diff`.
- `format` (string, optional): The output format pattern (e.g., `yyyy-MM-dd HH:mm`). standard Luxon tokens. Default: `ISO`. Shown when: operation = `format`.
- `amount` (integer, optional): Number of units to add (can be negative). Default: `0`. Shown when: operation = `add`.
- `unit` (string, optional): Default: `hours`. Allowed values: `minutes`, `hours`, `days`, `weeks`, `months`, `years`. Shown when: operation = `add` | `diff`.
- `to_value` (string, optional, accepts expressions): The second date for "Diff" operations. Shown when: operation = `diff`.
- `timezone` (string, optional): Target timezone for the operation. Default: `UTC`.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `out` (default): Operation successful
- `error`: Invalid date or format

## Input contract

- `value` (string, optional)
- `to_value` (string, optional)

## Output contract

- `result` (string | number, optional): The resulting date string or calculated difference.

## In expressions

What a later node can read from this node's output with `$("Date & Time").item.json.<path>` (write your node's label instead of `Date & Time`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Date & Time").item.json.result` (string | number) = `"2026-11-29T10:00:00.000-05:00"`: The resulting date string or calculated difference.
- `$("Date & Time").item.json.order_id` (string) = `"ord_123"` (Not suggested by the editor)
- `$("Date & Time").item.json.created_at` (string) = `"2026-11-26T15:00:00.000Z"` (Not suggested by the editor)


## How it works

Gets the current time, formats a date, adds time to a date or computes the difference between two dates with Luxon, and adds the value as `result` to the incoming payload.

1. Resolves the config with these defaults: `operation` `now`, `format` `ISO`, `amount` 0, `unit` `hours`, `timezone` `UTC`.
2. `now`: the current time in `timezone`, as ISO 8601.
3. `format`: parses `value` as ISO 8601, converts it to `timezone` and returns ISO 8601, or the Luxon pattern in `format` (for example `yyyy-MM-dd HH:mm`).
4. `add`: parses `value`, converts it to `timezone`, adds `amount` (converted to a number, negative allowed) in `unit` and returns ISO 8601. `format` is not applied.
5. `diff`: returns `value` minus `to_value` (default now) in `unit` as a number that can have decimals; positive when `value` is later. `timezone` is not used.
6. Returns the incoming payload plus `result` through `out`, and repeats the value in `meta.result`.

## In a workflow

### Node

```json
{
  "node_id": "node-due-date",
  "label": "Compute due date",
  "operator_slug": "data.datetime",
  "operator_version": "1.0.0",
  "config": {
    "operation": "add",
    "value": "{{ $json.created_at }}",
    "amount": 3,
    "unit": "days",
    "timezone": "America/Bogota"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "order_id": "ord_123",
    "created_at": "2026-11-26T15:00:00.000Z",
    "result": "2026-11-29T10:00:00.000-05:00"
  },
  "meta": {
    "result": "2026-11-29T10:00:00.000-05:00"
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The operation succeeded. `result` is a string, or a number for `diff`.

```json
{
  "order_id": "ord_123",
  "created_at": "2026-11-26T15:00:00.000Z",
  "result": "2026-11-29T10:00:00.000-05:00"
}
```

### `error`

A date is invalid or the operation is unknown.

```json
{
  "ok": false,
  "errors": [
    "Datetime Error: Invalid date: 26/11/2026 - unparsable"
  ],
  "port": "error"
}
```

## Behaviour in the code

- `value`: Only ISO 8601 strings are parsed (`2026-11-26`, `2026-11-26T15:00:00Z`). Other formats such as `26/11/2026` or epoch numbers fail.
- `timezone`: With an unknown zone, `now` returns `result: null` through `out` instead of failing.
- `unit`: Passed to Luxon as is, so other Luxon units such as `seconds` also work.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Datetime Error: Invalid date: <value> - <reason>` | `error` | `format` received a `value` that is not ISO 8601 (reason `unparsable`) or an unknown `timezone` (reason `unsupported zone`). |
| `Datetime Error: Invalid date: <value>` | `error` | `add` received an invalid `value` or `timezone`. |
| `Datetime Error: Invalid dates for diff` | `error` | `value` or `to_value` is not ISO 8601. |
| `Datetime Error: Unknown operation: <operation>` | `error` | `operation` is not `now`, `format`, `add` or `diff`. |

## Notes and limits

- An existing `result` key in the payload is overwritten.
- When the envelope has no `data` (or `data` is falsy), the engine stores the whole envelope as the node output: on `error` the next node receives `{ ok: false, errors: [...], port: "error" }` as its payload.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "data.datetime",
  "name": "Date & Time",
  "category": "data",
  "version": "1.0.0",
  "description": "Manipulates date and time values, offering formatting, calculations, and current time generation.\n\n  This utility does not rely on external services and uses the 'luxon' library for robust handling of timezones and formats.\n\n  **Operations:**\n  - **Now:** Returns the current date/time in the specified timezone.\n  - **Format:** Converts a date string into a specific format pattern.\n  - **Add:** Adds time (minutes, days, etc.) to a given date.\n  - **Diff:** Calculates the difference between two dates in a specific unit.\n\n  **Use Cases:**\n  - Generating timestamps for DB records.\n  - Calculating \"Due Date\" (Now + 7 Days).\n  - Formatting dates for email templates (e.g., \"Jan 01, 2024\").",
  "capabilities": [
    "utils",
    "date",
    "time",
    "luxon"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "operation": {
        "type": "string",
        "enum": [
          "now",
          "format",
          "add",
          "diff"
        ],
        "default": "now",
        "title": "Operation",
        "description": "The date operation to perform."
      },
      "value": {
        "type": "string",
        "title": "Input Date",
        "description": "The source date (ISO string). Required for Format, Add, and Diff.",
        "format": "expression",
        "displayOptions": {
          "show": {
            "operation": [
              "format",
              "add",
              "diff"
            ]
          }
        }
      },
      "format": {
        "type": "string",
        "title": "Format Pattern",
        "default": "ISO",
        "description": "The output format pattern (e.g., `yyyy-MM-dd HH:mm`). standard Luxon tokens.",
        "displayOptions": {
          "show": {
            "operation": [
              "format"
            ]
          }
        }
      },
      "amount": {
        "type": "integer",
        "default": 0,
        "title": "Amount to Add",
        "description": "Number of units to add (can be negative).",
        "displayOptions": {
          "show": {
            "operation": [
              "add"
            ]
          }
        }
      },
      "unit": {
        "type": "string",
        "enum": [
          "minutes",
          "hours",
          "days",
          "weeks",
          "months",
          "years"
        ],
        "default": "hours",
        "title": "Unit",
        "displayOptions": {
          "show": {
            "operation": [
              "add",
              "diff"
            ]
          }
        }
      },
      "to_value": {
        "type": "string",
        "title": "Compare Date",
        "description": "The second date for \"Diff\" operations.",
        "format": "expression",
        "displayOptions": {
          "show": {
            "operation": [
              "diff"
            ]
          }
        }
      },
      "timezone": {
        "type": "string",
        "default": "UTC",
        "ui_widget": "timezone_picker",
        "title": "Timezone",
        "description": "Target timezone for the operation."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    },
    "required": [
      "operation"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "value": {
        "type": "string"
      },
      "to_value": {
        "type": "string"
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": [
          "string",
          "number"
        ],
        "description": "The resulting date string or calculated difference."
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Output",
      "is_default": true,
      "description": "Operation successful"
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Invalid date or format"
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "date",
    "time",
    "utils"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "operation": {
      "type": "string",
      "enum": [
        "now",
        "format",
        "add",
        "diff"
      ],
      "default": "now",
      "title": "Operation",
      "description": "The date operation to perform."
    },
    "value": {
      "type": "string",
      "title": "Input Date",
      "description": "The source date (ISO string). Required for Format, Add, and Diff.",
      "format": "expression",
      "displayOptions": {
        "show": {
          "operation": [
            "format",
            "add",
            "diff"
          ]
        }
      }
    },
    "format": {
      "type": "string",
      "title": "Format Pattern",
      "default": "ISO",
      "description": "The output format pattern (e.g., `yyyy-MM-dd HH:mm`). standard Luxon tokens.",
      "displayOptions": {
        "show": {
          "operation": [
            "format"
          ]
        }
      }
    },
    "amount": {
      "type": "integer",
      "default": 0,
      "title": "Amount to Add",
      "description": "Number of units to add (can be negative).",
      "displayOptions": {
        "show": {
          "operation": [
            "add"
          ]
        }
      }
    },
    "unit": {
      "type": "string",
      "enum": [
        "minutes",
        "hours",
        "days",
        "weeks",
        "months",
        "years"
      ],
      "default": "hours",
      "title": "Unit",
      "displayOptions": {
        "show": {
          "operation": [
            "add",
            "diff"
          ]
        }
      }
    },
    "to_value": {
      "type": "string",
      "title": "Compare Date",
      "description": "The second date for \"Diff\" operations.",
      "format": "expression",
      "displayOptions": {
        "show": {
          "operation": [
            "diff"
          ]
        }
      }
    },
    "timezone": {
      "type": "string",
      "default": "UTC",
      "ui_widget": "timezone_picker",
      "title": "Timezone",
      "description": "Target timezone for the operation."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  },
  "required": [
    "operation"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "value": {
      "type": "string"
    },
    "to_value": {
      "type": "string"
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "result": {
      "type": [
        "string",
        "number"
      ],
      "description": "The resulting date string or calculated difference."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Output",
    "is_default": true,
    "description": "Operation successful"
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Invalid date or format"
  }
]
```
