# How to use logic operators on a date?

**URL:** <https://community.silverfin.com/t/how-to-use-logic-operators-on-a-date/235>\
**Category:** Templates\
**Tags:** variables, if, operators, attribute\_date\
**Created:** [May 4, 2017, 12:33pm UTC](https://community.silverfin.com/t/how-to-use-logic-operators-on-a-date/235 "2017-05-04T12:33:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GMOONS](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@GMOONS](https://community.silverfin.com/u/GMOONS)\
**Post date:** [May 4, 2017, 12:33pm UTC](https://community.silverfin.com/t/how-to-use-logic-operators-on-a-date/235/1 "2017-05-04T12:33:58Z")

</div>

Dear,

I believe it is interesting to know how to use logic formula’s on a date.  
Suppose I want to know if February 29 is part of my accounting period.

I tried to program it with the following code:  
´´´  
{% capture first\_date %}{% period.year\_start\_date as date: %d/%m/%y %}{% endcapture %}  
{% capture last\_date %}{% period.year\_end\_date as date: %d/%m/%y %}{% endcapture %}

{% if first\_date \<= ‘29/02/16’ and last\_date \>= ‘29/02/16’ %}{% assign z = 0 %}{% else %}{% assign z = 1 %} {% endif %}  
´´´  
However when I use this code when my period is 01/01/17-31/12/17 I still get z = 0.  
This is quite bothering me.

Someone an idea here?

Kind regards,

Glenn

---

<div class="post-metadata">

**Author:** ![Mathias](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/mathias/32/125_2.png) [@Mathias](https://community.silverfin.com/u/Mathias)\
**Post date:** [May 5, 2017, 11:16am UTC](https://community.silverfin.com/t/how-to-use-logic-operators-on-a-date/235/2 "2017-05-05T11:16:03Z")

</div>

Hello @GMOONS,

Could you please try to change the {% %} to {{ }} in the following elements that you capture in your code:  
{% period.year\_start\_date as date: %d/%m/%y %}  
{% period.year\_end\_date as date: %d/%m/%y %}

Your code should look like:

```auto
{% capture first_date %}{{ period.year_start_date as date: %d/%m/%y }}{% endcapture %}
{% capture last_date %}{{ period.year_end_date as date: %d/%m/%y }}{% endcapture %}

{% if first_date <= '29/02/16' and last_date >= '29/02/16' %}{% assign z = 0 %}{% else %}{% assign z = 1 %} {% endif %}

```

Kind regards,

Mathias
