[Solved] Count months from a specific date/month

I would like to count the months from a certain date, let’s say: october 2018. Is there a jinja2 solution to that?

Do you mean the number of months since October 2018 compared to today?

Yes indeed.

Do you want to account for the day of the month (both of the date and today)? Or just whole months (i.e., the number of times the month changed since then)?

What format do you have the date in?

Here’s one way:

{% set date = 'October 2018' %}
{% set date = strptime(date, '%B %Y') %}
{% set today = now() %}
{{ today.year*12+today.month - (date.year*12+date.month) }}
3 Likes

Hi Phil,

This was just what I was looking for. Thanks! I’m going to dive into the date.month commands.

Regards,

Wilfred

Glad I could help.

This is just Python. Both strptime and now return Python datetime objects. I’m just using standard datetime class attributes here.