In Directus Flow to Read-Data Operation: how to extract the month of now$ in a filter

736 Views Asked by At

Use Case: I have a collection with consulant with a field birhdate.

Now I want to create a flow to read all consultant who have birthday this month.

{
  "collection": "Consultant",
  "query": {
    "filter": {
      "month(birthdate)": {
        "_eq": "month($now)"
      }
    }
  }
}

Does not work!!!

When I hardcode the month it works nicely

{
  "collection": "Consultant",
  "query": {
    "filter": {
      "month(birthdate)": {
        "_eq": "7"
      }
    }
  }
}

Any suggenstions?

extract current month out of $now in a filter

1

There are 1 best solutions below

0
hamilton.lima On

From the Directus documentation, https://docs.directus.io/reference/filter-rules.html#dynamic-variables, you can see:

Although certain Operations in Flows use filter rules, dynamic variables are not available in Flows.

I would create an "Run Script" Operation to extract the month, and use it your filter. see https://docs.directus.io/app/flows/operations.html#run-script