Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the difference between 2 dates is > or < 1 month in Jinja2 templates?

I am using jinja2 templates (with Ansible) and in it i require to check the difference between two dates. I do not have the epoch of the dates but i do have them in yyy-mm-dd HH:MM:ss format (no milliseconds). So my questions:

1) Is there a way in jinja2 to compare two dates ? I do not want to install any library, it has to be a built in feature.

2) If it cannot be done via jinja2, is there a quick logic i can implement to compare them ? Like converting to epoch ? (remember, no milliseconds)

like image 461
ishan Avatar asked Aug 04 '16 07:08

ishan


1 Answers

Building on @konstantin-suvorov's answer, you'll want to use the to_datetime filter.

{{ (date1|to_datetime - date2|to_datetime).days }}
like image 101
Aidan Feldman Avatar answered May 19 '23 01:05

Aidan Feldman