I really hope someone can help me with this, I’ve been stuck for ages, even ChatGPT hasn’t been able to fix it.
I’ve set a date within my module called “business_start_date” and set it to the 1st July. I would now like to to loop through all 12 months using a range function, however it is missing out October and repeating March! I’m really puzzled why it’s doing this.
{% for month_no in range(1, 13) %}
{% set month_start = module.business_start_date | plus_time(month_no, "months") %}
{{ month_start | format_date('MMMM YYYY') }}<br>
{% endfor %}
ChatGPT can be rubbish for hubl tbh, a lot of the time it treats it as if it’s exactly the same as jinja.
But… your code seems to work for me. Here’s what it outputs:
August 2025
September 2025
October 2025
November 2025
December 2025
January 2026
February 2026
March 2026
April 2026
May 2026
June 2026
July 2026
Could your date format have something to do with it?
1st of July 2025 for my account is 01/07/2025
Just weird that it would work on my end but not yours, so maybe something to do with date formatting?
What are you seeing if you pprint your month_start in the loop?
Barry Grennan
Freelance HubSpot CMS Developer
Website | Contact | LinkedIn
Hey @ben-duchy,
Your code worked as expected on my end.
Here is a screenshot of the output.
If you are looking to loop from the chosen date, This code snippet worked for me,
{% set current_month = module.business_start_date %}
{% for month_no in range(0, 12) %}
{{ current_month | format_date('MMMM YYYY') }}<br>
{% set current_month = current_month | plus_time(1, "months") %}
{% endfor %}
Hope this will helps!
Best Regards,
Thanks @BarryGrennan & @kosalaindrasiri for testing this. It’s strange how you’re both getting the correct view and I’m not.
I’ve updated the code to yours @kosalaindrasiri but it’s still doing it, see screenshot. The 1st is the output from my original.
However, I have just dicsovered that if I change the date to the 2nd July, it displays all the months in the correct order with no duplications. Any idea why this fixes it?
A further discovery, if I add a timezone on either mine or @kosalaindrasiri example, it fixes it!
{{ current_month | format_date('MMMM YYYY', 'America/New_York') }}
Ok, I guess it’s to do with the timezone of your portal then.
Barry Grennan
Freelance HubSpot CMS Developer
Website | Contact | LinkedIn
You’re probably right, although under settings my account is set to UK date format and the timezone is UTC +00:00 London, unless there’s something I’ve missed?