# How to cast stat.mtime (float) to readable date-time

**URL:** <https://forum.ansible.com/t/how-to-cast-stat-mtime-float-to-readable-date-time/30099>\
**Category:** Ansible Project\
**Created:** [April 11, 2019, 2:36pm UTC](https://forum.ansible.com/t/how-to-cast-stat-mtime-float-to-readable-date-time/30099 "2019-04-11T14:36:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Griffiths](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@Jim\_Griffiths](https://forum.ansible.com/u/Jim_Griffiths)\
**Post date:** [April 11, 2019, 2:36pm UTC](https://forum.ansible.com/t/how-to-cast-stat-mtime-float-to-readable-date-time/30099/1 "2019-04-11T14:36:25Z")

</div>

I need to display the date-time that a file was last updated.

The value can be obtained with stat on the file:

- name: Get file stats

stat: path=“{{ path\_of\_file }}”

register: reg

- debug:

msg: “Timestamp of {{path}}: {{reg.stat.mtime}}”

However the output is meaningless because it is a float value.  
The only solution I could find requires the creation of a custom filter: [https://stackoverflow.com/questions/41084097/ansible-cast-float-to-date](https://stackoverflow.com/questions/41084097/ansible-cast-float-to-date)

Is there a simpler way?

Thank you all.  
Jim

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 11, 2019, 2:42pm UTC](https://forum.ansible.com/t/how-to-cast-stat-mtime-float-to-readable-date-time/30099/2 "2019-04-11T14:42:05Z")

</div>

You want something like this:

- debug:  
msg: “Timestamp of {{ path }}: {{ ‘%c’|strftime(reg.stat.mtime) }}”

Documentation about the strftime filter can be found at [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_filters.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html)

---

<div class="post-metadata">

**Author:** ![Jim\_Griffiths](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@Jim\_Griffiths](https://forum.ansible.com/u/Jim_Griffiths)\
**Post date:** [April 11, 2019, 7:30pm UTC](https://forum.ansible.com/t/how-to-cast-stat-mtime-float-to-readable-date-time/30099/3 "2019-04-11T19:30:54Z")

</div>

Thanks for the advice, Matt!

Here’s what I ended up using:

- debug:

msg: “Timestamp of {{logpath}}: {{ ' **%Y-%m-%d %H:%M:%S’ | strftime** (reg.stat.mtime) }}”

Cheers

Jim
