# how to compare two dates (possibly in different format) in jinja2 templates ?

**URL:** <https://forum.ansible.com/t/how-to-compare-two-dates-possibly-in-different-format-in-jinja2-templates/22155>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [July 28, 2016, 6:23pm UTC](https://forum.ansible.com/t/how-to-compare-two-dates-possibly-in-different-format-in-jinja2-templates/22155 "2016-07-28T18:23:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [July 28, 2016, 6:23pm UTC](https://forum.ansible.com/t/how-to-compare-two-dates-possibly-in-different-format-in-jinja2-templates/22155/1 "2016-07-28T18:23:34Z")

</div>

I am writing a template in which the warning output is generated if the winRM certificate of target windows host is going to expire in 1 month. I just don’t see a way how can i compare two dates in jinja2 template.

I have the winrm certificate expiration time in the fact - ansible\_winrm\_certificate\_expires

Now the comparison will look something like this in template:

Check WinRM certificate  
{% for i in play\_hosts %}  
{% **if hostvars[i].ansible\_winrm\_certificate\_expires compared to current date** %}  
{{ i }}: Warning - WinRM certificate expires in 1 month  
{% endif %}

{% endfor %}

Any way of comparing dates here ?
