Forum Discussion
DougHenning1
3 years agoCommunity Manager
You had the ')' before '.month' instead of after it, so the 'int' filter wasn't getting applied to the final value. Also, the formula I posted didn't always produce the correct result. Here's the corrected version with your dates cleaned up:
------------------------------
Doug Henning
------------------------------
{% set reportDate = time.now - time.delta(months=1) -%}
{% set year = reportDate.strftime('%y') -%}
{% set qtr = (((reportDate.month - 1) / 3) + 1) | int -%}
{{ "Report_Q%s%s_%s" | format(qtr, year, reportDate|date_mdy) }}
------------------------------
Doug Henning
------------------------------
JeromeMitchell
3 years agoQrew Member
Thanks, this worked great. Just had a minor question. in the qtr logic :
{% set qtr = (((reportDate.month - 1) / 3) + 1) | int -%}
can you explain the (((report.Date.month -1) /3) +1) part? why do you minus 1 then divide by 3 and add 1 again.
Thanks
------------------------------
Jerome Mitchell
------------------------------
{% set qtr = (((reportDate.month - 1) / 3) + 1) | int -%}
can you explain the (((report.Date.month -1) /3) +1) part? why do you minus 1 then divide by 3 and add 1 again.
Thanks
------------------------------
Jerome Mitchell
------------------------------
- DougHenning13 years agoCommunity ManagerGlad it worked! Dividing by 3 is because there are 3 months in a quarter (12/3 = 4). The adding and subtracting is to adjust for the math in the month division (month/3). Using the date 1/1/2023 for example, if you just did month/3 you'd get 0.33 which rounds to 0.
I found this solution online that works as well:
{% set qtr = (reportDate.month/3) | round(method='ceil') | int %}
------------------------------
Doug Henning
------------------------------- PrashantMaheshw3 years agoQrew CaptainHI Doug,
Thanks for the compliment ! Appreciated , glad to know about the custom filters by QuickBase super handy.
I also have a small question . What does %s in below mean ?
{{ "Report_Q%s%s_%s" | format(qtr, year, reportDate|date_mdy) }}
------------------------------
Prashant Maheshwari
------------------------------- DougHenning13 years agoCommunity ManagerHi Prashant, the format filter uses printf-style formatting, so the %s means replace with a string. There are three %s representing the three variables passed to format.
------------------------------
Doug Henning
------------------------------