Do you mean 1 Dec 2024 or 12 Jan 2024; or perhaps 1 Dec 2023 with a typo? Suggest using internationally unambiguous date descriptions like those, or ISO8601 yyyy-mm-dd format.
Simple way is int(days / (365.25 / 12)); but if you need to be exact on calendar months that might give the wrong answer. With my guess that you mean 1 Dec 2023:
If you want to count âall calendar months that have happened since the timestamp including the start and current monthsâ, something like this should do it:
{% set t0 = ("2024-01-12"|as_datetime) %}
{% set t1 = now() %}
{% set y0 = t0.year %}
{% set m0 = t0.month %}
{% set y1 = t1.year %}
{% set m1 = t1.month %}
{{ (13 - m0) + (12 * (y1 - y0 - 1)) + m1 }}
(13-m0) is months in the timestampâs year
(12 * (y1 - y0 - 1)) counts months in any full years between the two dates
m1 is the number of months in the current year
Here, you get 13 for 12 Jan 2024, as it includes two Januarys plus all the other 2024 months.
6-Jan-2024 is 0 months and 5 days from 1-Jan-2024.
6-Feb-2024 is 1 month and 5 days.
âŽ
6-Dec-2024 is 11 months and 5 days
6-Jan-2025 is 12 months and 5 days
Only if youâre doing âinclusive countingâ like my example above, which ignores days altogether, would you be on 13 months by now. In that example, 31-Jan-2024 to 1-Feb-2024 would be 2 months even though the actual timespan could be a few seconds: