Skip to main content

Duration

The Duration function calculates the duration between two datetimes, expressed in the configured unit.

If the from datetime is more recent than the to datetime, the step fails (DateFromIsMoreRecentThanTo) — the function never returns a negative result.

Parameters

Unitrequired

The time unit for the output. Accepted values are the lowercase strings microsecond, millisecond, second, minute, hour, day, week, month, year. Note these differ from the capitalized units used by DateAdd / DateSubtract.

Input

from datetimerequired

The start date and time. Accepts a Datetime value only (not a Date).

to datetimerequired

The end date and time. Accepts a Datetime value only (not a Date).

Output

Number

The duration between the two datetimes, expressed in the configured unit.

info

month and year are calendar-based deltas, not fixed-length divisions: month counts whole calendar months using year/month arithmetic (minus one if the to day of month is smaller than the from day), and year counts whole elapsed years between the two dates.