Skip to content

tm_timeadd Function โ€‹

tm_timeadd adds a duration to a timestamp, returning a new timestamp.

hcl
tm_timeadd(timestamp, duration)

In the Terraform language, timestamps are conventionally represented as strings using RFC 3339 "Date and Time format" syntax. tm_timeadd requires the timestamp argument to be a string conforming to this syntax.

duration is a string representation of a time difference, consisting of sequences of number and unit pairs, like "1.5h" or "1h30m". The accepted units are "ns", "us" (or "ยตs"), "ms", "s", "m", and "h". The first number may be negative to indicate a negative duration, like "-2h5m".

The result is a string, also in RFC 3339 format, representing the result of adding the given direction to the given timestamp.

Examples โ€‹

sh
tm_timeadd("2017-11-22T00:00:00Z", "10m")
2017-11-22T00:10:00Z
  • tm_formatdate can convert the resulting timestamp to other date and time formats.
  • tm_timecmp compares two timestamps and returns a number that represents the ordering of the instants those timestamps represent.
  • tm_timestamp returns a string representation of the current date and time.