# Calculate Elapsed Time

**URL:** <https://forum.ansible.com/t/calculate-elapsed-time/44848>\
**Category:** Get Help\
**Created:** [November 17, 2025, 8:15am UTC](https://forum.ansible.com/t/calculate-elapsed-time/44848 "2025-11-17T08:15:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![StefanSchnell](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/stefanschnell/32/9353_2.png) [@StefanSchnell](https://forum.ansible.com/u/StefanSchnell)\
**Post date:** [November 17, 2025, 8:15am UTC](https://forum.ansible.com/t/calculate-elapsed-time/44848/1 "2025-11-17T08:15:15Z")

</div>

Hello all, 👋

today I tried to calculate the elapsed time of a module execution in a playbook.

Here an example code:

```auto
- name: Get start time
  ansible.builtin.set_fact:
    startTime: "{{ now() }}"

- name: The module to be measured
  ...

- name: Get end time
  ansible.builtin.set_fact:
    endTime: "{{ now() }}"

- name: Try to calculate elapsed time, but it does not work
  ansible.builtin.debug:
    msg: "{{ (endTime - startTime) }}"

```

Unfortunately I have not found a way to calculate the elapsed time.

Now I have two questions:

1. What would be the correct approach for calculating with times?
2. Is there another or better approach to measure the elapsed time of module executions in a playbook?

Thanks for hints and tips.  
Best regards  
Stefan

---

<div class="post-metadata">

**Author:** ![Lyle\_McKarns](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lyle_mckarns/32/8142_2.png) [@Lyle\_McKarns](https://forum.ansible.com/u/Lyle_McKarns)\
**Post date:** [November 17, 2025, 2:27pm UTC](https://forum.ansible.com/t/calculate-elapsed-time/44848/2 "2025-11-17T14:27:17Z")

</div>

Check out the [profile tasks](https://docs.ansible.com/projects/ansible/latest/collections/ansible/posix/profile_tasks_callback.html) callback.

It provides information on how much time was spent on each task in line, and a summary at the end.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [November 17, 2025, 3:31pm UTC](https://forum.ansible.com/t/calculate-elapsed-time/44848/3 "2025-11-17T15:31:24Z")

</div>

what @Lyle_McKarns is the best approach, yours could work, but you are not giving any indication no ‘how it does not work’ so it is very hard to give you a solution.

Normally you want to give the exact error and if possible extended verbose and/or debug information when asking for help.

---

<div class="post-metadata">

**Author:** ![StefanSchnell](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/stefanschnell/32/9353_2.png) [@StefanSchnell](https://forum.ansible.com/u/StefanSchnell)\
**Post date:** [November 17, 2025, 4:11pm UTC](https://forum.ansible.com/t/calculate-elapsed-time/44848/4 "2025-11-17T16:11:53Z")

</div>

Hello Brian [@bcoca],

thanks for your reply. Yep, my mistake, the error is:

```plaintext
Type 'timedelta' is unsupported for variable storage.

```

This brings me to the solution:

```auto
- name: Print start and end time
  ansible.builtin.debug:
    msg: "{{ (endTime.timestamp() - startTime.timestamp()) }}"

```

Best regards  
Stefan

---

<div class="post-metadata">

**Author:** ![StefanSchnell](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/stefanschnell/32/9353_2.png) [@StefanSchnell](https://forum.ansible.com/u/StefanSchnell)\
**Post date:** [November 17, 2025, 4:14pm UTC](https://forum.ansible.com/t/calculate-elapsed-time/44848/5 "2025-11-17T16:14:27Z")

</div>

Hello Lyle, [@Lyle_McKarns],  
thanks for your reply and your excellent tip, great to know that.  
Best regards  
Stefan

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 17, 2025, 4:14pm UTC](https://forum.ansible.com/t/calculate-elapsed-time/44848/6 "2025-12-17T16:14:32Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
