# Filter data by date range

**URL:** <https://community.hubspot.com/t/filter-data-by-date-range/40570>\
**Category:** CMS Development\
**Tags:** hubdb\
**Created:** [July 12, 2021, 11:21am UTC](https://community.hubspot.com/t/filter-data-by-date-range/40570 "2021-07-12T11:21:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [July 12, 2021, 11:21am UTC](https://community.hubspot.com/t/filter-data-by-date-range/40570/1 "2021-07-12T11:21:07Z")

</div>

I’ve been tasked with displaying rows based on a set of date ranges with an overall number of how many rows meet this criteria. This date range will need to be editable within the page editor but for now I can’t even get a hard coded version to work!

I thought something along these lines, but no luck!

```lia-code-sample
{% set table = hubdb_table_rows(12345467) %}

{% for row in table %}
 {% set plot = unixtimestamp(row.plot_date) %}
 {% set startdate1 = "01/07/2021"|strtodate("dd/MM/yyyy") %}
 {% set enddate1 = "30/09/2021"|strtodate("dd/MM/yyyy") %}

 {% if plot | datetimeformat('%e/%m/%Y') >= startdate1 %}
 {% if plot | datetimeformat('%e/%m/%Y') <= enddate1 %}
 Display row data
 {% endif %}
 {% endif %}

 {% endfor %}

```

To summerise, it should show:

- Between 1 July 2020 – 30 September 2020
  - Unsold Plots = 10
    - Row(s) information displayed

  - Reserved plots = 20
    - Row(s) information displayed

  - Exchanged plots = 25
    - Row(s) information displayed

Total plots = 55

Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Indra](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/indra/32/98381_2.png) [@Indra](https://community.hubspot.com/u/Indra)\
**Post date:** [July 13, 2021, 6:25am UTC](https://community.hubspot.com/t/filter-data-by-date-range/40570/2 "2021-07-13T06:25:46Z")

</div>

Hi @ben-duchy,

Did you check your previous question?  
[https://community.hubspot.com/t5/CMS-Development/Finding-the-length-of-repeating-dates/td-p/457184](https://community.hubspot.com/t5/CMS-Development/Finding-the-length-of-repeating-dates/td-p/457184)

It’s best to format your date by numbers so you can compare if it’s a larger of lower number. So best thing to do it to set your date up by %Y%m%d.

Your code will look like this:

```lia-code-sample
{% set rows = hubdb_table_rows(1234567, "&plot_status __in=Completed&forecast_year__ in=20/21") %}

{% set items = {'amount' : 0 } %}

{% for row in rows %}

 {% set cur = row["legal_completion"]|datetimeformat('%Y%m%d') %}
 {% set from = module.from_date|datetimeformat('%Y%m%d') %}
 {% set till = module.till_date|datetimeformat('%Y%m%d') %}

 {% if from <= cur && cur <= till %}
 {% do items.update({'amount' : items.amount + 1}) %}
 {% endif %}
{% endfor %}

Items in range: {{ items.amount }}

```

---

<div class="post-metadata">

**Author:** ![Indra](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/indra/32/98381_2.png) [@Indra](https://community.hubspot.com/u/Indra)\
**Post date:** [July 13, 2021, 12:56pm UTC](https://community.hubspot.com/t/filter-data-by-date-range/40570/3 "2021-07-13T12:56:35Z")

</div>

@ben-duchy can you mark this topic as solved if this solved your problem?

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [July 13, 2021, 1:05pm UTC](https://community.hubspot.com/t/filter-data-by-date-range/40570/4 "2021-07-13T13:05:21Z")

</div>

My apologies, yes of course 🙂
