# Counting months

Is there an easy way to calculate for a date that is some months later or earlier?

e.g. consider 3 months later. I have for instance 30/11/2016 and I would like to use 28/02/2017 for a check. Or I have 31/08/2016 and then I need to calculate 30/11/2016 to do my check. Since 3 months is not just 180days, I don’t see an easy way to do this.

I think I can manage something using a combination of different date-formats, but I guess I would need very much code to do this.

So, would there be an easy way to get this done?

Hello @Warde,

As you probably know, there is a way in Silverfin to check on a period (and their begin- and end date) if they exist or not. But I have a feeling that’s not what you’re looking for. You want to check on the end-date of every month, no matter which frequency you use (month, quarter or year) in Silverfin ?

However, I’m not sure if I understand the case you’re going for here from an accountancy standpoint. Can you give me more info on this?

Indeed Sven, that’s not really what I am looking for.

If I check for the end of period date, I for instance get 31/03/2017. I then like to do a check on the date 6 months later (e.g. filing of the annual account), which means that I need to get 30/09/2017. As I mentioned, since this is not just 180d later, I don’t see an easy way to calculate for this 30/09/2017 date…

Hey @Warde,

It’s indeed not an easy way to do it, but it is possible with below code (as example, we’ll calculate with adding 3 months):

{% assign day = period.end_date | date:"%d" %}
{% assign month = period.end_date | date:"%m" %}
{% assign year = period.end_date | date:"%y" %}

{% assign add_months = 3 %}

{% assign month = month | plus:add_months %}

{% assign month = INT(month) %}  {{ month }}

{% if month > 12 %}
{% assign month = month | minus:12 %}
{% assign year = year | plus:1 %}
{% endif %}

{% if day+0 > 28 %}
{% if month == 2 %}
{% assign schrikkel4 = year | modulo:4 %}
{% assign schrikkel100 = year | modulo:100 %}
{% assign schrikkel400 = year | modulo:400 %}
{% assign schrikkel = false %}
{% if schrikkel4 == 0 %}{% assign schrikkel = true %}{% endif %}
{% if schrikkel100 == 100 %}{% assign schrikkel = false %}{% endif %}
{% if schrikkel400 == 400 %}{% assign schrikkel = true %}{% endif %}
{% if schrikkel %}
{% assign day = 29 %}
{% else %}
{% assign day = 28 %}
{% endif %}
{% elsif month == 4 or month == 6 or month == 9 or month == 11 %}
{% assign day = 30 %}
{% else %}
{% assign day = 31 %}
{% endif %}
{% endif %}
{% capture show_day %}{% if INT(day) < 10 %}0{{day}}{% else %}{{day}}{% endif %}{% endcapture %}  {{ show_day }}
{% capture show_month %}{% if INT(month) < 10 %}0{{month}}{% else %}{{month}}{% endif %}{% endcapture %}  {{ show_month }}
{% capture this_date %}{{show_day}}/{{show_month}}/{{year}}{% endcapture %}

Calculated date :

{{ this_date }}

But this is a lot of code for a simple task IMO, so we’ll add this to the feature list that we can create some extra coding on our end (an extra filter or some sort you can use easily without doing above code).
This is also the reason I’m not gonna create a case out of this, because it doesn’t add easy use of Liquid code.

(credits to @Samwise for this)

Thanks for this Sven (& Sam)!

Ward