Skip to content

Time

Parse, shift and generate RFC 3339 timestamps.

formatdate

formatdate(format, timestamp) → string

Format a timestamp using a format string.

Uses HCL’s format spec: YYYY (year), MM (month), DD (day), hh (hour), mm (minute), ss (second).

ParameterTypeDescription
formatstring
timestampstringRFC3339 timestamp.
formatdate("YYYY-MM-DD", "2026-04-20T12:30:00Z")

→ "2026-04-20"

now

impure
now() → string

Return the current UTC time as an RFC3339 string.

Evaluated at expression-evaluation time. Two now() calls in the same action body may differ by microseconds.

now()

→ "2026-04-20T12:00:00Z"

timeadd

timeadd(timestamp, duration) → string

Add a Go duration to a timestamp.

ParameterTypeDescription
timestampstringRFC3339 timestamp.
durationstringGo duration (e.g. “6h”, “30m”).
timeadd("2026-01-01T00:00:00Z", "24h")

→ "2026-01-02T00:00:00Z"

timerandom

impure
timerandom(start, end) → string

Return a random timestamp between start and end.

ParameterTypeDescription
startstringRFC3339 timestamp (inclusive).
endstringRFC3339 timestamp (exclusive).
timerandom(timesub(now(), "30d"), now())

timesequence

impure
timesequence(start, end, min_interval, max_interval...) → list(string)

Generate timestamps stepping by random intervals between min and max.

Produces timestamps from start until end is reached. With only min_interval, steps are evenly spaced. With both min and max, each step is randomised within the range. Capped at 100,000 entries.

ParameterTypeDescription
startstringRFC3339 timestamp.
endstringRFC3339 timestamp.
min_intervalstringMinimum step duration.
max_interval...stringMaximum step duration (optional).
timesequence(timesub(now(), "30d"), now(), "1d", "5d")

timeseries

timeseries(start, end, count) → list(string)

Distribute exactly N timestamps evenly between start and end.

First entry is start, last is end, intermediate points are equidistant. Use timesequence for interval-based generation.

ParameterTypeDescription
startstringRFC3339 timestamp.
endstringRFC3339 timestamp.
countnumberNumber of timestamps to generate.
timeseries(timesub(now(), "90d"), now(), 10)

→ ["2026-01-20T...", ..., "2026-04-20T..."]

timesub

timesub(timestamp, duration) → string

Subtract a duration from a timestamp.

Supports extended durations: d (days = 24h) and w (weeks = 7d) on top of Go’s standard units.

ParameterTypeDescription
timestampstringRFC3339 timestamp.
durationstringDuration (e.g. “30d”, “2w”, “6h”).
timesub("2026-04-20T00:00:00Z", "7d")

→ "2026-04-13T00:00:00Z"

timeunix

timeunix(timestamp) → number

Convert a timestamp to Unix epoch seconds.

ParameterTypeDescription
timestampstringRFC3339 timestamp.
timeunix("2026-01-01T00:00:00Z")

→ 1767225600