I have a Hubdb table on which one column is a date and time field. Is it possible to filter the table to fetch rows by year so for example fetch rows where the year is 2018 in the date and time field?
{% set start = "2018-01-01T00:00:00+0000"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %}
{% set end = "2018-12-31T23:59:59+0000"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %}
{% set query = query ~ "&date_time__gte=" ~ start ~ "&date_time__lte=" ~ end ~ "&orderBy=date_time" %} {# assuming here you may have other queries #}
{% set table = hubdb_table_rows(table_id, query) %}
{% for row in table %}
{{row}}
{% endfor %}
Or you could loop over your table and use an if statement to check for year, which is a bit more readable. Like this:
{% set table = hubdb_table_rows(table_id, query) %} {# assuming here you may have other queries #}
{% for row in table|sort(False, False, 'date_time') %}
{% if row.date_time|datetimeformat('%Y') == '2018' %}
{{row}}
{% endif %}
{% endfor %}
{% set start = "2018-01-01T00:00:00+0000"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %}
{% set end = "2018-12-31T23:59:59+0000"|strtotime("yyyy-MM-dd'T'HH:mm:ssZ")|unixtimestamp %}
{% set query = query ~ "&date_time__gte=" ~ start ~ "&date_time__lte=" ~ end ~ "&orderBy=date_time" %} {# assuming here you may have other queries #}
{% set table = hubdb_table_rows(table_id, query) %}
{% for row in table %}
{{row}}
{% endfor %}
Or you could loop over your table and use an if statement to check for year, which is a bit more readable. Like this:
{% set table = hubdb_table_rows(table_id, query) %} {# assuming here you may have other queries #}
{% for row in table|sort(False, False, 'date_time') %}
{% if row.date_time|datetimeformat('%Y') == '2018' %}
{{row}}
{% endif %}
{% endfor %}