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!
{% 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 %}
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:
{% 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 }}
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:
{% 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 }}