Calculating with dates

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

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

Hi Katrien

I am wondering if this solved your problem?

Kind regards
Sam

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

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

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

{% capture BoekjaarIsKalenderjaar %} {{period.year_end_date|date:’%d/%m’}} {% endcapture %}

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

@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 !!

Hello @Andrew,

Could this help more?


{% 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 :relaxed:

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

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

I understand your explination.

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

Thx!

@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 for more info if needed) :


{% 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?

Nice!! It works.

Thx for your help !