How to dynamically set the created date value filter in the advanced query

Topic summary

A user needed to dynamically filter orders by the current month’s date range in a Shopify Flow advanced query, rather than manually updating hardcoded dates each month.

Original Problem:

  • The query used static dates (e.g., created_at:>=2025-06-01T00:00:00Z AND created_at:<=2025-06-30T23:59:59Z)
  • Manual monthly updates were impractical

Proposed Workaround:
The user considered building a backend service (AWS-hosted) to update order metafields monthly with dynamic date values via GraphQL mutations.

Solution Provided:
Shopify Flow supports date filters using Liquid templating:

{% assign first_day = "now" | date: "%Y-%m-01T00:00:00Z" %}
{% assign last_day = first_day | date_plus: "1 month" | date_minus: "1 second" %}

This automatically calculates the current month’s first and last day without external services or manual intervention.

Status: Resolved. The user confirmed the solution worked.

Summarized with AI on October 27. AI used: claude-sonnet-4-5-20250929.

I want to dynamically set the datetime in the created_at filter to the current month’s first day and last day in the flow. currently, the information is hard-coded.

Here’s my shopify flow:

In the Get Order Data Action, here’s the script of in advanced query:

{{order.customer.id}}> AND created_at:>=2025-06-01T00:00:00Z> AND created_at:<=2025-06-30T23:59:59Z

Is there a way to dynamically change the value when next month comes? I can’t manually set the value in the flow every month even if I make a scheduled reminder. Manually changing is OPTION 1.

OPTION 2: My other idea is to create a backend (hosted in AWS) that can run once a month that updates the the order’s metafield like first_day_of_the_month and last_day_of_the_month.

The backend app will call a graphQL mutation to update. here’s the flow:

  1. the backend app accepts customer ID or all order will be updated

  2. Get all orders as we need the order ID to use in the graphql to update its metafield

  3. Update the metafields using mutation

Or is there a simpler way to do it?

Yep, Shopify Flow has date-filters specifically to handle stuff like this.

{% assign first_day = "now" | date: "%Y-%m-01T00:00:00Z" %}
{% assign last_day = first_day | date_plus: "1 month" | date_minus: "1 second" %}

{{order.customer.id}}
AND created_at:>={{ first_day }}
AND created_at:<={{ last_day }}

Should do the trick nicely.

Running a testflow in my own store the query looks like this with the above filter:

{
  "field_name": "orders",
  "api_version": "2024-07",
  "query_args": {
    "sortKey": "CREATED_AT",
    "reverse": false,
    "query": "\n\n\ngid://shopify/Customer/8495132475578\nAND created_at:>=2025-06-01T00:00:00Z\nAND created_at:<=2025-06-30T23:59:59Z"
  },
  "max_root_records": 10
}

More info here: https://help.shopify.com/en/manual/shopify-flow/concepts/variables#filters

2 Likes

@Deathmel0n

Thank you so much for your help!