Files
opentf/website/docs/language/functions/timestamp.mdx
Martin Atkins dc9bec611c website: Reorganize and tidy some lifecycle-related information
Over time the discussion about "lifecycle" blocks in the documentation
became confusing because the docs originally written for managed resource
lifecycle got partially generalized for resources of other modes and for
module calls, even though each of those has a completely different
lifecycle and thus a different set of lifecycle settings.

This is a first pass at trying to reorganize that so that the "lifecycle"
page is really just an index of all of the different kinds of lifecycle
block that exist in the language, while the main documentation for each
use of that block type now belongs with the documentation of the block
it's nested within.

While working on this I also found that there was some duplication inside
the "data sources" page where the same information was described multiple
times, and a few other cases where things had become inconsistent over
time. This also includes a little extra content to try to clarify the
difference between managed, data, and ephemeral resources and to make it
explicit that the "Resources" section is focused only on managed resources
because that is the primary resource mode.

As usual there's lots more that could be done here -- this documentation
has gradually evolved over time and is full of weird quirks due to that
evolution -- but I decided to draw a line here so that the diff wouldn't
get too large.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-17 15:08:14 -07:00

42 lines
1.6 KiB
Plaintext

---
sidebar_label: timestamp
description: |-
The timestamp function returns a string representation of the current date
and time.
---
# `timestamp` Function
`timestamp` returns a UTC timestamp string in [RFC 3339](https://tools.ietf.org/html/rfc3339) format.
In the OpenTofu language, timestamps are conventionally represented as
strings using [RFC 3339](https://tools.ietf.org/html/rfc3339)
"Date and Time format" syntax, and so `timestamp` returns a string
in this format.
The result of this function will change every second, so using this function
directly with resource attributes will cause a diff to be detected on every
OpenTofu run. We do not recommend using this function in resource attributes,
but in rare cases it can be used in conjunction with
[the `ignore_changes` lifecycle meta-argument](../../language/resources/behavior.mdx#ignore_changes)
to take the timestamp only on initial creation of the resource. For more stable
time handling, see the [Time Provider](https://registry.terraform.io/providers/hashicorp/time).
Due to the constantly changing return value, the result of this function cannot
be predicted during OpenTofu's planning phase, and so the timestamp will be
taken only once the plan is being applied.
## Examples
```
> timestamp()
2018-05-13T07:44:12Z
```
## Related Functions
* [`formatdate`](../../language/functions/formatdate.mdx) can convert the resulting timestamp to
other date and time formats.
* [`plantimestamp`](../../language/functions/plantimestamp.mdx) will return a consistent timestamp
representing the date and time during the plan.