# ansible.builtin.strftime
Using Python’s `strftime` function, take a data formating string and a date/time to create a formated date.

## Parameters
| Parameter  | Type              | Description                                         |
| ---------- | ----------------- | --------------------------------------------------- |
| **Input**  | string / required | A formating string following `stftime` conventions. |
| **second** | integer           | Datetime in seconds from `epoch` to format, if not supplied `gmttime/localtime` will be used.                                                    |

## Examples
```yml
# for a complete set of features go to  https://strftime.org/

# Display year-month-day
{{ '%Y-%m-%d' | strftime }}
# => "2021-03-19"

# Display hour:min:sec
{{ '%H:%M:%S' | strftime }}
# => "21:51:04"

# Use ansible_date_time.epoch fact
{{ '%Y-%m-%d %H:%M:%S' | strftime(ansible_date_time.epoch) }}
# => "2021-03-19 21:54:09"

# Use arbitrary epoch value
{{ '%Y-%m-%d' | strftime(0) }}          # => 1970-01-01
{{ '%Y-%m-%d' | strftime(1441357287) }} # => 2015-09-04

# complex examples
vars:
  date1: '2022-11-15T03:23:13.686956868Z'
  date2: '2021-12-15T16:06:24.400087Z'
  date_short: '{{ date1|regex_replace("([^.]+)(\.\d{6})(\d*)(.+)", "\1\2\4") }}' #shorten microseconds
  iso8601format: '%Y-%m-%dT%H:%M:%S.%fZ'
  date_diff_isoed: '{{ (date1|to_datetime(isoformat) - date2|to_datetime(isoformat)).total_seconds() }}'
```