• Help Desk reporting gives you real-time visibility into your support operation without the manual work. Ask our experts about which metrics matter most! AMA Dec 8-12.

    Ask us anything

Re: Range function to display months

ben-duchy
Top Contributor

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 %}

 

0 Upvotes
1 Accepted solution
ben-duchy
Solution
Top Contributor

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') }}

 

View solution in original post

6 Replies 6
ben-duchy
Solution
Top Contributor

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') }}

 

BarryGrennan
Key Advisor

Ok, I guess it's to do with the timezone of your portal then.

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

 

 

0 Upvotes
ben-duchy
Top Contributor

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?

0 Upvotes
ben-duchy
Top Contributor

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?

Screenshot 2025-10-28 at 09.14.45.png

kosalaindrasiri
Top Contributor | Partner
Top Contributor | Partner

Hey @ben-duchy,

 

Your code worked as expected on my end.

Here is a screenshot of the output.

kosalaindrasiri_0-1761595457830.png

 

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,

Kosala Indrasiri

CEO

Sanmark Solutions
Linkedin
Kosala Indrasiri
emailAddress
kosala@thesanmark.com
website
www.sanmarksolutions.com
linkedinwhatsapp
Book a Consultation

Did my post help answer your question? Mark this as a solution.

0 Upvotes
BarryGrennan
Key Advisor

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?


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn



0 Upvotes