# CASE: how to compare dates

**URL:** https://community.silverfin.com/t/case-how-to-compare-dates/2322
**Category:** Cases
**Tags:** dates
**Created:** [July 22, 2022, 12:13pm UTC](https://community.silverfin.com/t/case-how-to-compare-dates/2322 "2022-07-22T12:13:31Z")
**Posts on this page:** 1
**Page:** 1

<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: [July 22, 2022, 12:13pm UTC](https://community.silverfin.com/t/case-how-to-compare-dates/2322/1 "2022-07-22T12:13:31Z")

</div>

When comparing dates, it’s a good practise to format the dates to a specific date format (check out our overview [here](https://developer.silverfin.com/docs/date#date)). The reason behind this, is that the dates can have a different format from one another, causing any comparison logic to be faulty.

An example would be comparing an input variable with a date from the period drop:

- input with the date attribute will be formatted as “dd/mm/yyyy” by default (so 14/02/2022)
- period drop dates are formatted as “yyyy-mm-dd (eg. period.end\_date will give 2022-12-31)

As you can see, comparing 14/02/2022 with 2022-12-31 won’t work due to the different date format. Obviously, if you have 2 variables already in the same format by default (eg. comparing 2 input variables with the date attribute), the comparison logic will work.

However, a good Liquid guideline would be to always format a date to the specific date filter `%F` which converts any date to a yyyy-mm-dd format.

So for our example:

```auto
{% comment %}format all dates to the same date format so compare logic can be executed{% endcomment %}
{% assign date_gm = custom.report_gm.date_report | date:"%F" %}
{% assign end_date_period = period.end_date | date:"%F" %}

{% comment %}create warning when date repport is BEFORE the actual end date of a period{% endcomment %}
{% if date_gm <= end_date_period %}
{% ic %}{::warningtext}
The date of the report General Meeting can not be set before the enddate of the period
{:/warningtext}{% endic %}
{% endif %}

```

More info can be found [here](https://developer.silverfin.com/docs/date#comparing-with-dates) as well.
