github.com/hugorut/terraform@v1.1.3/website/docs/language/functions/formatdate.mdx (about) 1 --- 2 page_title: formatdate - Functions - Configuration Language 3 description: The formatdate function converts a timestamp into a different time format. 4 --- 5 6 # `formatdate` Function 7 8 `formatdate` converts a timestamp into a different time format. 9 10 ```hcl 11 formatdate(spec, timestamp) 12 ``` 13 14 In the Terraform language, timestamps are conventionally represented as 15 strings using [RFC 3339](https://tools.ietf.org/html/rfc3339) 16 "Date and Time format" syntax. `formatdate` requires the `timestamp` argument 17 to be a string conforming to this syntax. 18 19 ## Examples 20 21 ``` 22 > formatdate("DD MMM YYYY hh:mm ZZZ", "2018-01-02T23:12:01Z") 23 02 Jan 2018 23:12 UTC 24 > formatdate("EEEE, DD-MMM-YY hh:mm:ss ZZZ", "2018-01-02T23:12:01Z") 25 Tuesday, 02-Jan-18 23:12:01 UTC 26 > formatdate("EEE, DD MMM YYYY hh:mm:ss ZZZ", "2018-01-02T23:12:01-08:00") 27 Tue, 02 Jan 2018 23:12:01 -0800 28 > formatdate("MMM DD, YYYY", "2018-01-02T23:12:01Z") 29 Jan 02, 2018 30 > formatdate("HH:mmaa", "2018-01-02T23:12:01Z") 31 11:12pm 32 ``` 33 34 ## Specification Syntax 35 36 The format specification is a string that includes formatting sequences from 37 the following table. This function is intended for producing common 38 _machine-oriented_ timestamp formats such as those defined in RFC822, RFC850, 39 and RFC1123. It is not suitable for truly human-oriented date formatting 40 because it is not locale-aware. In particular, it can produce month and day 41 names only in English. 42 43 The specification may contain the following sequences: 44 45 | Sequence | Result | 46 | -------- | ----------------------------------------------------------------------- | 47 | `YYYY` | Four (or more) digit year, like "2006". | 48 | `YY` | The year modulo 100, zero padded to at least two digits, like "06". | 49 | `MMMM` | English month name unabbreviated, like "January". | 50 | `MMM` | English month name abbreviated to three letters, like "Jan". | 51 | `MM` | Month number zero-padded to two digits, like "01" for January. | 52 | `M` | Month number with no padding, like "1" for January. | 53 | `DD` | Day of month number zero-padded to two digits, like "02". | 54 | `D` | Day of month number with no padding, like "2". | 55 | `EEEE` | English day of week name unabbreviated, like "Monday". | 56 | `EEE` | English day of week name abbreviated to three letters, like "Mon". | 57 | `hh` | 24-hour number zero-padded to two digits, like "02". | 58 | `h` | 24-hour number unpadded, like "2". | 59 | `HH` | 12-hour number zero-padded to two digits, like "02". | 60 | `H` | 12-hour number unpadded, like "2". | 61 | `AA` | Hour AM/PM marker in uppercase, like "AM". | 62 | `aa` | Hour AM/PM marker in lowercase, like "am". | 63 | `mm` | Minute within hour zero-padded to two digits, like "05". | 64 | `m` | Minute within hour unpadded, like "5". | 65 | `ss` | Second within minute zero-padded to two digits, like "09". | 66 | `s` | Second within minute, like "9". | 67 | `ZZZZZ` | Timezone offset with colon separating hours and minutes, like "-08:00". | 68 | `ZZZZ` | Timezone offset with just sign and digit, like "-0800". | 69 | `ZZZ` | Like `ZZZZ` but with a special case "UTC" for UTC. | 70 | `Z` | Like `ZZZZZ` but with a special case "Z" for UTC. | 71 72 Any non-letter characters, such as punctuation, are reproduced verbatim in the 73 output. To include literal letters in the format string, enclose them in single 74 quotes `'`. To include a literal quote, escape it by doubling the quotes. 75 76 ``` 77 > formatdate("h'h'mm", "2018-01-02T23:12:01-08:00") 78 23h12 79 > formatdate("H 'o''clock'", "2018-01-02T23:12:01-08:00") 80 11 o'clock 81 ``` 82 83 This format specification syntax is intended to make it easy for a reader 84 to guess which format will result even if they are not experts on the syntax. 85 Therefore there are no predefined shorthands for common formats, but format 86 strings for various RFC-specified formats are given below to be copied into your 87 configuration as needed: 88 89 - [RFC 822](https://tools.ietf.org/html/rfc822#section-5) and 90 [RFC RFC 2822](https://tools.ietf.org/html/rfc2822#section-3.3): 91 `"DD MMM YYYY hh:mm ZZZ"` 92 - [RFC 850](https://tools.ietf.org/html/rfc850#section-2.1.4): 93 `"EEEE, DD-MMM-YY hh:mm:ss ZZZ"` 94 - [RFC 1123](https://tools.ietf.org/html/rfc1123#section-5.2.14): 95 `"EEE, DD MMM YYYY hh:mm:ss ZZZ"` 96 - [RFC 3339](https://tools.ietf.org/html/rfc3339): 97 `"YYYY-MM-DD'T'hh:mm:ssZ"` (but this is also the input format, so such a 98 conversion is redundant.) 99 100 ## Related Functions 101 102 - [`format`](/language/functions/format) is a more general formatting function for arbitrary 103 data. 104 - [`timestamp`](/language/functions/timestamp) returns the current date and time in a format 105 suitable for input to `formatdate`.