Is there any way of setting a dynamic default value?

I've been trying to use a dynamic default value, as in this case for setting the default date to the current date, but I don't manage to get it to work...


{% form %}

  type: date
  default: 2017-10-01

  type: date
  default: current_date

{% endform %}

I know there is a tutorial on that you can make the type to text and use "today" and some if-clauses etc., but I'm not interested in that, I want the type to be date.

Is this possible in any way?

4replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi Andreas ,

    If you don't include a default, the date parameter should use today's date in the report UI.  If you're looking to set a default date value to run in the query editor, you an use syntax like this.  This example gives you the date 7 days ago:

    {% form %}
      type: date
      default: {{'now' | date: "%Y"}}-{{'now' | date: "%m"}}-{{'now' | date: "%d" | minus: 7}}
    {% endform %}
    Reply Like 1
  • Hello Donna McGahan 

    The syntax you posted worked really good! Thanks!

    Reply Like
  • Hello again Donna McGahan!

    This doesn't work when the month is January. Doing this:

    default: {{'now' | date: "%Y"}}-{{'now' | date: "%m" | minus: 1}}-{{'now' | date: "%d"}}

    Will result in the following:


    Reply Like
  • Hi Andreas Rolén - sorry for the delayed response. A different approach may solve for this case:

      type: date
      default: {{ 'now' | date: '%s' | minus: 604800 | date: '%Y-%m-%d' }}

    There are also more examples of using Liquid to create a calculated date in our documentation:

    Hope that helps - please do reach out to our success team via in-product chat or if we can be of further assistance. Thanks!

    Reply Like
Like Follow
  • Status Answered
  • 1 yr agoLast active
  • 4Replies
  • 921Views
  • 3 Following