Nodes/Basic data handling/Time Difference
ComfyUI Node

Time Difference

The 'How Long Between These Two Dates?' Node

By StableLlama·Created about a year ago·Updated 4 days ago· 48
Time Difference
  • datetime1
  • datetime2
  • TIMEDELTA

"How long between then and now?" is one of the most useful questions in automation, and Time Difference is the node that answers it. It takes two DATETIME objects, subtracts the second from the first, and returns the gap as a TIMEDELTA - which you can then format, compare, or display however you like.

How it works

From StableLlama's Basic data handling pack. Two required inputs:

  • datetime1 - the "from" end of the interval.
  • datetime2 - the "to" end.

The math is literally datetime1 - datetime2, and the order matters: it's not absolute. If datetime1 is before datetime2, you get a negative TIMEDELTA. For an always-positive "elapsed time," arrange your inputs so the later value is first, or just be aware of the sign.

Output: one TIMEDELTA object - the duration. From there you can't directly display it as text, but you can feed it into the pack's tools or chain it onward. It's the same TIMEDELTA type that Create Time Delta produces, so it's interchangeable with hand-built durations in the add/subtract nodes.

What people actually do with it

  • Elapsed time measurement - Time Now at the start of a render and Time Now at the end... except in ComfyUI both "now" values update every run, so the practical version is comparing a parsed timestamp against the current time: how old is this file, how many days since this log entry.
  • Age checks - parse a date from a filename or metadata, subtract it from TimeNow, and use the result to decide whether to re-run something.
  • Interval validation - is the gap between two events within an acceptable window?

The classic flow: TimeParse (text → DATETIME) on one side, TimeNow on the other, TimeDifference between them, and the result feeds a comparison or a log string.

Installing it

Search "Basic data handling" in ComfyUI Manager and restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart and it's available. No dependencies, no models.

Gotchas

Two things. First, the sign convention - datetime1 minus datetime2, so get your order right or every result will be mysteriously negative. Second, the output is a TIMEDELTA, not text: to see "3 days, 2:00:00" in a readable form you'll format it yourself or just use it in arithmetic. And if you're comparing against a UTC value from TimeNowUTC and a naive value from TimeParse, the timezone mismatch can throw - keep both sides in the same frame.

CategoryBasic/time

Inputs (2)

NameTypeDefaultDescription
datetime1DATETIME
datetime2DATETIME

Outputs (1)

NameTypeDescription
TIMEDELTATIMEDELTA