# date module is not working as expected

**URL:** <https://forum.ansible.com/t/date-module-is-not-working-as-expected/29671>\
**Category:** Ansible Project\
**Created:** [February 13, 2019, 4:08pm UTC](https://forum.ansible.com/t/date-module-is-not-working-as-expected/29671 "2019-02-13T16:08:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinod93pop](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@vinod93pop](https://forum.ansible.com/u/vinod93pop)\
**Post date:** [February 13, 2019, 4:08pm UTC](https://forum.ansible.com/t/date-module-is-not-working-as-expected/29671/1 "2019-02-13T16:08:02Z")

</div>

HI team,

I have a below playbook, where it works fine if I enter dates manually in vars. but it fails when passing through register. tried max possibilities.

need your help

- hosts: one  
become: true  
tasks:
- shell: " dsmc query filespace / | tail -n 1 | awk ‘{print$2}’"  
register: backup
- shell: “date +‘%Y-%m-%d’”  
register: today
- shell: “date -d ‘{{backup.stdout}}’ +‘%Y-%m-%d’”  
register: test
- set\_fact:  
date1: “{{test.stdout}}”  
date2: “{{today.stdout}}”
- debug:  
msg: “{{date1}} and {{date2}}”
- template:  
src: /home/viraj4/ansible/date.j2  
dest: /tmp/date.txt
- shell: “cat /tmp/date.txt”  
register: date
- debug:  
msg: “{{ date.stdout }}”
- shell: “\> /tmp/date.txt”  
[viraj4@\*\*\*\*\*\*\*\*\* ansible]$ cat /home/viraj4/ansible/date.j2  
{{ (date1 - date2).days }}  
output:  
TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* =\> {  
“msg”: “2019-02-13 and 2019-02-13”  
}  
Perform task: TASK: template (N)o/(y)es/(c)ontinue: y  
Perform task: TASK: template (N)o/(y)es/(c)ontinue: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
TASK [template] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*]: FAILED! =\> {“changed”: false, “msg”: “AnsibleError: Unexpected templating type error occurred on ({{ (date1 - date2).days }}\n): unsupported operand type(s) for -: ‘AnsibleUnsafeText’ and ‘AnsibleUnsafeText’”}  
to retry, use: --limit @/home/viraj4/ansible/time.retry
