Jan 31, 2023 11:09 AM
How do I get last month as a filter for a HubDB?
{% set current_month = local_dt|datetimeformat("%m") %}
{% set current_year = local_dt|datetimeformat("%y") %}
{% set previous_month = ????|datetimeformat("%m") %}
{% set previous_year = ????|datetimeformat("%y") %}
Feb 1, 2023 11:05 AM
{% set current_month = local_dt|datetimeformat("%m") %}
{% set current_year = local_dt|datetimeformat("%y") %}
{% set previous_month = current_month|default(1)|int - 1 %}
{% set previous_year = current_year|int - 1 %}
{% if previous_month == 0 %}
{% set previous_month = 12 %}
{% endif %}
Test: {{ previous_month }}, {{ previous_year }}, {{ current_year }}
This should return: 1, 22, 23
since today is Feb 1, 2023
You can use those numbers as filters for the values in your query:
{{ set query = "year=" + previous_year }}
{{ hubdb_table_rows(<tableId>, query) }}
Hope that helps!