2018-05-13 21:49:05 +02:00
|
|
|
---
|
2021-12-15 03:41:17 +01:00
|
|
|
page_title: timestamp - Functions - Configuration Language
|
2018-05-13 21:49:05 +02:00
|
|
|
description: |-
|
|
|
|
The timestamp function returns a string representation of the current date
|
|
|
|
and time.
|
|
|
|
---
|
|
|
|
|
|
|
|
# `timestamp` Function
|
|
|
|
|
2020-05-21 23:29:38 +02:00
|
|
|
`timestamp` returns a UTC timestamp string in [RFC 3339](https://tools.ietf.org/html/rfc3339) format.
|
2018-05-13 21:49:05 +02:00
|
|
|
|
|
|
|
In the Terraform 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
|
|
|
|
Terraform run. We do not recommend using this function in resource attributes,
|
|
|
|
but in rare cases it can be used in conjunction with
|
2021-12-15 03:41:17 +01:00
|
|
|
[the `ignore_changes` lifecycle meta-argument](/language/meta-arguments/lifecycle#ignore_changes)
|
2020-09-14 22:40:36 +02:00
|
|
|
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/).
|
2018-05-13 21:49:05 +02:00
|
|
|
|
|
|
|
Due to the constantly changing return value, the result of this function cannot
|
2019-09-05 19:08:34 +02:00
|
|
|
be predicted during Terraform's planning phase, and so the timestamp will be
|
2018-05-13 21:49:05 +02:00
|
|
|
taken only once the plan is being applied.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```
|
|
|
|
> timestamp()
|
|
|
|
2018-05-13T07:44:12Z
|
|
|
|
```
|
2019-01-04 02:58:56 +01:00
|
|
|
|
|
|
|
## Related Functions
|
|
|
|
|
2021-12-15 03:41:17 +01:00
|
|
|
* [`formatdate`](/language/functions/formatdate) can convert the resulting timestamp to
|
2019-01-04 02:58:56 +01:00
|
|
|
other date and time formats.
|