github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/functions/formatdate.html.md (about)

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