How to format date and time in terraform?

You can use terraform formatdate() function to format date and time in terraform. formatdate() converts a timestamp into a different time format.

Syntax: formatdate(specification, timestamp)

The format specification is a string that includes formatting sequences from the following table.

specificationoutcome
YYYYFour (or more) digit year, like “2006”.
YYThe year modulo 100, zero padded to at least two digits, like “06”.
MMMMEnglish month name unabbreviated, like “January”.
MMMEnglish month name abbreviated to three letters, like “Jan”.
MMMonth number zero-padded to two digits, like “01” for January.
MMonth number with no padding, like “1” for January.
DDDay of month number zero-padded to two digits, like “02”.
DDay of month number with no padding, like “2”.
EEEEEnglish day of week name unabbreviated, like “Monday”.
EEEEnglish day of week name abbreviated to three letters, like “Mon”.
hh24-hour number zero-padded to two digits, like “02”.
h24-hour number unpadded, like “2”.
HH12-hour number zero-padded to two digits, like “02”.
H12-hour number unpadded, like “2”.
AAHour AM/PM marker in uppercase, like “AM”.
aaHour AM/PM marker in lowercase, like “am”.
mmMinute within hour zero-padded to two digits, like “05”.
mMinute within hour unpadded, like “5”.
ssSecond within minute zero-padded to two digits, like “09”.
sSecond within minute, like “9”.
ZZZZZTimezone offset with colon separating hours and minutes, like “-08:00”.
ZZZZTimezone offset with just sign and digit, like “-0800”.
ZZZLike ZZZZ but with a special case “UTC” for UTC.
ZLike ZZZZZ but with a special case “Z” for UTC.

Examples:

Leave a Reply

Close Menu