APIs & Integrations

Anonymous
Nicht anwendbar

hubdb filter for last month/year

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") %}

0 Upvotes
1 Antwort
Brownstephen101
Stratege/Strategin | Elite Partner
Stratege/Strategin | Elite Partner

hubdb filter for last month/year

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

0 Upvotes