# Date Time Conversion

**URL:** <https://forum.ansible.com/t/date-time-conversion/38261>\
**Category:** Ansible Project\
**Created:** [July 26, 2023, 9:09am UTC](https://forum.ansible.com/t/date-time-conversion/38261 "2023-07-26T09:09:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![javed\_khan\_siddque](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/javed_khan_siddque/32/4964_2.png) [@javed\_khan\_siddque](https://forum.ansible.com/u/javed_khan_siddque)\
**Post date:** [July 26, 2023, 9:09am UTC](https://forum.ansible.com/t/date-time-conversion/38261/1 "2023-07-26T09:09:14Z")

</div>

Hi All,

I want to convert the below time to human readable format, i tried some of the jinza formatter but it is failing .  
Failed  
{{ iso\_date|iso8601\_to\_time|datetimeformat(‘%a, %B %d’) }}  
requirement 2023-07-20 16:36:44

So i can convert this to \<file\_name\>\_2023\_07\_20\_16\_36\_44 .txt

“created”: “2023-07-20T16:36:44.396234Z”, “modified”: “2023-07-20T16:37:26.400464Z”,

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [July 26, 2023, 3:52pm UTC](https://forum.ansible.com/t/date-time-conversion/38261/2 "2023-07-26T15:52:35Z")

</div>

I would use `regex_replace` instead -

```auto
- debug:
msg: '{{ iso_date |regex_replace("(\d{4})\-(\d{2})\-(\d{2})\ (\d{2}):(\d{2}):(\d{2})", " _____.txt") }}'
vars:
iso_date: "2023-07-20 16:36:44"

```

---

<div class="post-metadata">

**Author:** ![Andrew\_Latham](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Latham](https://forum.ansible.com/u/Andrew_Latham)\
**Post date:** [July 26, 2023, 6:19pm UTC](https://forum.ansible.com/t/date-time-conversion/38261/3 "2023-07-26T18:19:38Z")

</div>

- [https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior](https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior)
- [https://github.com/ansible/ansible/blob/devel/lib/ansible/template/ **init**.py#L829-L839](https://github.com/ansible/ansible/blob/devel/lib/ansible/template/ __init__.py#L829-L839)

typed without testing, sorry, give it a go

- name: create my file  
ansible.builtin.file:  
path: /tmp/{{ now(fmt=“%Y\_%m\_%d\_%H\_%M\_%S.txt”) }}  
state: touch

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [July 26, 2023, 7:25pm UTC](https://forum.ansible.com/t/date-time-conversion/38261/4 "2023-07-26T19:25:38Z")

</div>

```auto
      path: /tmp/"{{ now(fmt="%Y_%m_%d_%H_%M_%S.txt") }}"

```

should be

```auto
      path: /tmp/{{ now(fmt="%Y_%m_%d_%H_%M_%S.txt") }}

```
