# Calculating with dates

**URL:** <https://community.silverfin.com/t/calculating-with-dates/370>\
**Category:** Templates\
**Tags:** math, attribute\_date\
**Created:** [August 11, 2017, 3:04pm UTC](https://community.silverfin.com/t/calculating-with-dates/370 "2017-08-11T15:04:14Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Katrien](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/katrien/32/117_2.png) [@Katrien](https://community.silverfin.com/u/Katrien)\
**Post date:** [August 11, 2017, 3:04pm UTC](https://community.silverfin.com/t/calculating-with-dates/370/1 "2017-08-11T15:04:14Z")

</div>

Why the if statement never ends in AJ+1 node ?

```
{{period.year_end_date}}
{% capture BoekjaarIsKalenderjaar %} {{period.year_end_date | date:'%d/%m' }} {% endcapture %}
Einddatum boekjaar : {{BoekjaarIsKalenderjaar}} 

{% capture AJ %} {{period.year_end_date | date:'%Y'}} {% endcapture %}
Aanslagjaar : {{AJ}}

{% if boekjaarIsKalenderjaar == '31/12' %} AJ+1 : {% capture intrest_key %}intrest_{{period.year_end_date+365 | date:'%Y'}}{% endcapture %} {{period.year_end_date+365 | date:'%Y'}}
{% else%} AJ : {% capture intrest_key %}intrest_{{period.year_end_date | date:'%Y'}}{% endcapture %} {{period.year_end_date | date:'%Y'}} {% endif %}

{{intrest_key}}
```

---

<div class="post-metadata">

**Author:** ![SamVanEenoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/samvaneenoo/32/134_2.png) [@SamVanEenoo](https://community.silverfin.com/u/SamVanEenoo)\
**Post date:** [August 12, 2017, 7:58am UTC](https://community.silverfin.com/t/calculating-with-dates/370/3 "2017-08-12T07:58:15Z")

</div>

Hi Katrien

There are 2 reasons why this code is not working.

The first one is that variables are case sensitive. You are using “BoekjaarIsKalenderjaar” with a capital B to define your variable but “boekjaarIsKalenderjaar” without a capital b when you make a check on it with your if statement.

> BoekjaarIsKalenderjaar != boekjaarIsKalenderjaar

The second problem is that you are using spaces in your capture. Boekjaar is defined as " 31/12 " in your capture and your if statement is checking for “31/12”. These spaces do make a difference.

> " 31/12 " != “31/12”

Try adjusting your code with previous tips and let us know if it worked.

Kind regards  
Sam

---

<div class="post-metadata">

**Author:** ![SamVanEenoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/samvaneenoo/32/134_2.png) [@SamVanEenoo](https://community.silverfin.com/u/SamVanEenoo)\
**Post date:** [August 21, 2017, 12:22pm UTC](https://community.silverfin.com/t/calculating-with-dates/370/4 "2017-08-21T12:22:53Z")

</div>

Hi Katrien

I am wondering if this solved your problem?

Kind regards  
Sam

---

<div class="post-metadata">

**Author:** ![Katrien](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/katrien/32/117_2.png) [@Katrien](https://community.silverfin.com/u/Katrien)\
**Post date:** [August 21, 2017, 1:07pm UTC](https://community.silverfin.com/t/calculating-with-dates/370/5 "2017-08-21T13:07:15Z")

</div>

Did not have the time to test, but I suppose it will.  
looks evident that’s the cause.

---

<div class="post-metadata">

**Author:** ![Katrien](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/katrien/32/117_2.png) [@Katrien](https://community.silverfin.com/u/Katrien)\
**Post date:** [August 25, 2017, 11:35am UTC](https://community.silverfin.com/t/calculating-with-dates/370/6 "2017-08-25T11:35:59Z")

</div>

Problem not solved, the variables are equal written, and the value of BoekjaarIsKalenderjaar does not contain spaces if i do a preview.

> {% comment %} Bedrag is per AJ (AJ 2017 → inkomsten 2016) {% endcomment %}  
> {% assign intrest\_2017 = 0.2018 %}  
> {% assign intrest\_2017 = 0.0927 %}  
> {% assign intrest\_2016 = 0.0816 %}  
> {% assign intrest\_2015 = 0.0920 %}
> 
> {% t= “Datum” fr:“Date” %}  
> {% t= “Omschrijving” fr:“Description” %}  
> {% t= “Waarde” fr:“Valeur” %}  
> {% t= “Intrestberekening per” fr:“Calcul d’intérêts par” %}  
> {% t= “Datum” fr:“Date” %}  
> {% t= “Saldo” fr:“Solde” %}
> 
> {{period.year\_end\_date}}  
> {% capture BoekjaarIsKalenderjaar %} {{period.year\_end\_date|date:‘%d/%m’}} {% endcapture %}  
> Einddatum boekjaar : ‘{{BoekjaarIsKalenderjaar}}’  
> {% capture AJ %} {{period.year\_end\_date|date:‘%Y’}} {% endcapture %}  
> Aanslagjaar : {{AJ}}
> 
> {% if BoekjaarIsKalenderjaar == ‘31/12’ %} AJ+1 : {% capture intrest\_key %}intrest\_{{period.year\_end\_date+365 | date:‘%Y’}}{% endcapture %} {{period.year\_end\_date+365 | date:‘%Y’}}  
> {% else%} AJ : {% capture intrest\_key %}intrest\_{{period.year\_end\_date | date:‘%Y’}}{% endcapture %} {{period.year\_end\_date | date:‘%Y’}}  
> {% endif %}
> 
> {{intrest\_key}}

---

<div class="post-metadata">

**Author:** ![Katrien](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/katrien/32/117_2.png) [@Katrien](https://community.silverfin.com/u/Katrien)\
**Post date:** [August 25, 2017, 11:39am UTC](https://community.silverfin.com/t/calculating-with-dates/370/7 "2017-08-25T11:39:50Z")

</div>

Solved, the problem is the space after te %} end the {{perioid

{% capture BoekjaarIsKalenderjaar %} {{period.year\_end\_date|date:’%d/%m’}} {% endcapture %}

---

<div class="post-metadata">

**Author:** ![SamVanEenoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/samvaneenoo/32/134_2.png) [@SamVanEenoo](https://community.silverfin.com/u/SamVanEenoo)\
**Post date:** [August 25, 2017, 11:46am UTC](https://community.silverfin.com/t/calculating-with-dates/370/8 "2017-08-25T11:46:27Z")

</div>

> [@Katrien](#):
>
> {% comment %} Bedrag is per AJ (AJ 2017 -\> inkomsten 2016) {% endcomment %}
> 
> {% assign intrest\_2017 = 0.2018 %}
> 
> {% assign intrest\_2017 = 0.0927 %}
> 
> {% assign intrest\_2016 = 0.0816 %}
> 
> {% assign intrest\_2015 = 0.0920 %}
> 
> {% t= “Datum” fr:“Date” %}
> 
> {% t= “Omschrijving” fr:“Description” %}
> 
> {% t= “Waarde” fr:“Valeur” %}
> 
> {% t= “Intrestberekening per” fr:“Calcul d’intérêts par” %}
> 
> {% t= “Datum” fr:“Date” %}
> 
> {% t= “Saldo” fr:“Solde” %}
> 
> {{period.year\_end\_date}}
> 
> {% capture BoekjaarIsKalenderjaar %} {{period.year\_end\_date|date:’%d/%m’}} {% endcapture %}
> 
> Einddatum boekjaar : ‘{{BoekjaarIsKalenderjaar}}’
> 
> {% capture AJ %} {{period.year\_end\_date|date:’%Y’}} {% endcapture %}
> 
> Aanslagjaar : {{AJ}}
> 
> {% if BoekjaarIsKalenderjaar == ‘31/12’ %} AJ+1 : {% capture intrest\_key %}intrest\_{{period.year\_end\_date+365 | date:’%Y’}}{% endcapture %} {{period.year\_end\_date+365 | date:’%Y’}}
> 
> {% else%} AJ : {% capture intrest\_key %}intrest\_{{period.year\_end\_date | date:’%Y’}}{% endcapture %} {{period.year\_end\_date | date:’%Y’}}
> 
> {% endif %}
> 
> {{intrest\_key}}

Dag Katrien

Het probleem ligt deze keer aan het gebruik van de quotes, je kan zowel enkele als dubbele gebruiken maar bij de enkele quotes zijn er 2 verschillende namelijk ` en ’  
Enkel de tweede soort kan werken. Je kan ook zoals in onderstaand voorbeeld dubbele quotes gebruiken.

> {% comment %} Bedrag is per AJ (AJ 2017 → inkomsten 2016) {% endcomment %}  
> {% assign intrest\_2017 = 0.2018 %}  
> {% assign intrest\_2017 = 0.0927 %}  
> {% assign intrest\_2016 = 0.0816 %}  
> {% assign intrest\_2015 = 0.0920 %}
> 
> {% t= “Datum” fr:“Date” %}  
> {% t= “Omschrijving” fr:“Description” %}  
> {% t= “Waarde” fr:“Valeur” %}  
> {% t= “Intrestberekening per” fr:“Calcul d’intérêts par” %}  
> {% t= “Datum” fr:“Date” %}  
> {% t= “Saldo” fr:“Solde” %}
> 
> {{period.year\_end\_date}}  
> {% capture BoekjaarIsKalenderjaar %}{{period.year\_end\_date|date:“%d/%m”}}{% endcapture %}  
> Einddatum boekjaar : “{{BoekjaarIsKalenderjaar}}”  
> {% capture AJ %}{{period.year\_end\_date|date:“%Y”}}{% endcapture %}  
> Aanslagjaar : {{AJ}}
> 
> {% if BoekjaarIsKalenderjaar == “31/12” %} AJ+1 : {% capture intrest\_key %}intrest\_{{period.year\_end\_date+365 | date:“%Y”}}{% endcapture %} {{period.year\_end\_date+365 | date:“%Y”}}  
> {% else%} AJ : {% capture intrest\_key %}intrest\_{{period.year\_end\_date | date:’%Y’}}{% endcapture %} {{period.year\_end\_date | date:’%Y’}}  
> {% endif %}
> 
> {{intrest\_key}}

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://community.silverfin.com/u/Andrew)\
**Post date:** [March 28, 2018, 9:38pm UTC](https://community.silverfin.com/t/calculating-with-dates/370/9 "2018-03-28T21:38:31Z")

</div>

@sven

Hi Sven,

question - i want to generate a date in one of our tempates 1d + 5Y.

I have used following code

{% input custom.some.date as:date %}

{% assign current\_date = custom.some.date %}

{% assign date\_days = current\_date+1 | date:"%d/%m/%Y" %}  
{% assign year = current\_date | date:"%Y" %}  
{% assign year\_5 = year | plus:5 %}

{% capture date %}{{ date\_days | date:"%d/%m" }}/{{ year\_5 }}{% endcapture %}

At the place i want the date I just then put {{ date }}

This works, but the problem I’m facing now, is that he takes all the dates from the first line in the whole template.  
I have multiple dates in multiple lines, so every outcome 1d + 5Y has to be different.

Do you have a solution ?

Thx in advance !!

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [April 2, 2018, 2:55pm UTC](https://community.silverfin.com/t/calculating-with-dates/370/10 "2018-04-02T14:55:45Z")

</div>

Hello @Andrew,

Could this help more?

```auto

{% input custom.some.date as:date %}

{% assign original_date = custom.some.date | date:'%s' %}

seconds since 1970-01-01 00:00:00 UTC = {{ original_date }}

{% assign 5_years_1_day = 157871030 %}

{% assign new_date = original_date | plus:5_years_1_day %}

test new date = {{ new_date | date:"%d/%m/%Y" }}

```

The `%s` show a date in the amount of seconds from the date of 1/1/1970.  
The variable `5_years_1_day` is what I created to add the amount of seconds that equals 5 years and 1 day.  
I’ll add this to my original date and add a date filter on it to display the correct date-format.

There are other ways to play with dates though, but does this by any chance solves your issue? Not quite sure if I understood your issue by your posted code 😌

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://community.silverfin.com/u/Andrew)\
**Post date:** [April 2, 2018, 6:52pm UTC](https://community.silverfin.com/t/calculating-with-dates/370/11 "2018-04-02T18:52:09Z")

</div>

Thx Sven!

It’s not really what i’m looking for.

I have following code. If I give in my date, I want the date in {{date}} to be calculated 5Y + 1d.

With current code I get always the same date. If I use a second line with another date, the date has to be different of course. Could you help me out ?

{% assign current\_date = custom.some.date %}

{% assign date\_days = current\_date+1 | date:"%d/%m/%Y" %}  
{% assign year = current\_date | date:"%Y" %}  
{% assign year\_5 = year | plus:5 %}

{% capture date %}{{ date\_days | date:"%d/%m" }}/{{ year\_5 }}{% endcapture %}

| {% t “Boekjaar van aanleg of terugname” %} | |{% t “Aanslagjaar” %} | {% t “Aangelegd” %} | {% t “Terugname” %} | {% t “Uitkeerbaar à 5% RV vanaf” %} |{% t “Saldo” %}  
|-------|-------:|-----------:|-------15%-----:|-----15%-------:|-------|-----15%-----:+{% fori detail in current\_account.details %}  
|{% input custom.some.date as:date %} |{% input detail.custom.file as:file %} |{% input detail.custom.aanslagjaar %}|{% $1+input detail.value placeholder:“aangelegd” as:currency %}|{% $2+input detail.custom.terugname as:currency %}|{{ date }}|{% =$0+ detail.value-detail.custom.terugname %}{% endfori %}  
| | | | **{{ $1 | currency }}** | **{{ $2 | currency }}** | | **{{ $0 | currency }}** {% unexplained $0+current\_account.value %}

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [April 3, 2018, 7:27am UTC](https://community.silverfin.com/t/calculating-with-dates/370/12 "2018-04-03T07:27:19Z")

</div>

Ow okay @Andrew, now I understand.

Your whole logic around that date, should be done within your fori-loop. It makes sense to do so, because for each loop a new date has to be calculated.

Because you did this outside the fori-loop in the beginning, the variable `{{ date }}` will indeed give the same result, no matter what loop you’re in.

Care to give it a try? Let me know if you’re stuck with my explanation

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://community.silverfin.com/u/Andrew)\
**Post date:** [April 3, 2018, 8:11am UTC](https://community.silverfin.com/t/calculating-with-dates/370/13 "2018-04-03T08:11:14Z")

</div>

I understand your explination.

Where do you integrate the code in the fori-loop ? At the beginning or end ?

Thx!

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [April 3, 2018, 8:23am UTC](https://community.silverfin.com/t/calculating-with-dates/370/14 "2018-04-03T08:23:00Z")

</div>

@Andrew,

Within your fori-loop, after you generate your custom input-date. Like this for example (I added stripnewlines so you’ll see it better - see [here](https://community.silverfin.com/t/update-structure-newline-tag/366) for more info if needed) :

```auto

{% stripnewlines %}
{% newline %}
| {% t “Boekjaar van aanleg of terugname” %} | |{% t “Aanslagjaar” %} | {% t “Aangelegd” %} | {% t “Terugname” %} | {% t “Uitkeerbaar à 5% RV vanaf” %} |{% t “Saldo” %}
{% newline %}
|-------|-------:|-----------:|-------15%-----:|-----15%-------:|-------|-----15%-----:+
{% fori detail in current_account.details %}
{% newline %}
| {% input detail.custom.date as:date %} 
| {% input detail.custom.file as:file %} 
| {% input detail.custom.aanslagjaar %}
| {% $1+input detail.custom.value placeholder:“aangelegd” as:currency %}
| {% $2+input detail.custom.terugname as:currency %}
  
  {% assign current_date = detail.custom.date %}

  {% assign date_days = current_date+1 | date:"%d/%m/%Y" %}
  {% assign year = current_date | date:"%Y" %}
  {% assign year_5 = year | plus:5 %}

  {% capture date %}{{ date_days | date:"%d/%m" }}/{{ year_5 }}{% endcapture %}
  
| {{ date }}
| {% =$0+ detail.custom.value-detail.custom.terugname %}
{% endfori %}
{% newline %}
| | | | {{ $1 | currency }} | {{ $2 | currency }} | |{{ $0 | currency }}{% unexplained $0+current_account.value %}
{% endstripnewlines %} 

```

Be aware that I changed your custom objects into `detail.custom` everywhere! Because your are putting in custom objects into a drop that is ours (the details-drop) so if you want to write down custom objects in there, you need to use `.custom` .

One little suggestion: your code will always generate a date, even a date hasn’t been inputted. So I’d suggest putting that whole logic code into an if-statement (check if the input-date is blank or not), so you won’t see a wierd date generated while no input has been made.

Hope this helps?

---

<div class="post-metadata">

**Author:** ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://community.silverfin.com/u/Andrew)\
**Post date:** [April 3, 2018, 9:46am UTC](https://community.silverfin.com/t/calculating-with-dates/370/15 "2018-04-03T09:46:00Z")

</div>

Nice!! It works.

Thx for your help !
