SQL模式:动态日期参数



我正在尝试使用模式SQL创建一个参数,该参数将动态到当前月份的第一个和最后一个日期作为开始和结束日期。我把我的代码放在下面,我知道它不起作用。您必须使用Liquid SQL(https://mode.com/help/articles/parameters/#dynamic-选项列表(。

{% form %}
start_date:
type: date
default: date_add(month, -1, date_trunc(month, current_date))

end_date:
type: date
default: LAST_DAY(TO_DATE(CURRENT_DATE,YYYY-MM-DD))
{% endform %}

这里有一个技巧性的方法。在月1日效果很好,但在月底效果不太好,因为月底会更改日期。

{% form %}
start_date:
type: date
default: {{ 'now' | date: '%s' | date: '%Y-%m-01' }}
description: Only display data after this date.

end_date:
type: date
default: {{ 'now' | date: '%s' | date: '%Y-%m-30' }}
description: Only display data before this date.
{% endform %}

最新更新