How can we filter based on only month and day using queryFilter?

Hello,

The data in my database is of form yyyy-mm-dd. While filtering data, I want to ignore the year. How can I do it?

Thanks.

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    That is not possible out of the box. I suggest to implement a view in database which puts day, month and year into separate columns. Then you can filter on this. In case your data volume is large, consider performance tests.

  • 0
    Certified Lead Developer
    in reply to Stefan Helzle

    I'd argue that using an a!queryLogicalExpression() with an "OR" operator and some looping logic could work for this use case, OOB, for a "brute force" approach, assuming there is a finite-and-discernable number of years "back" the query needs to reach (and assuming it's not a large number).

    Example:

    a!localVariables(
      /* number of years to look back */
      local!numYears: 10,
      
      local!month: 6,
      local!day: 27,
      
      a!queryLogicalExpression(
        operator: "OR",
        filters: {
          a!forEach(
            enumerate(local!numYears),
            
            a!queryFilter(
              field: "myDate",
              operator: "=",
              value: date(
                year(today()) - fv!item,
                local!month,
                local!day
              )
            )
          )
        }
      )
    )

    result:

Reply
  • 0
    Certified Lead Developer
    in reply to Stefan Helzle

    I'd argue that using an a!queryLogicalExpression() with an "OR" operator and some looping logic could work for this use case, OOB, for a "brute force" approach, assuming there is a finite-and-discernable number of years "back" the query needs to reach (and assuming it's not a large number).

    Example:

    a!localVariables(
      /* number of years to look back */
      local!numYears: 10,
      
      local!month: 6,
      local!day: 27,
      
      a!queryLogicalExpression(
        operator: "OR",
        filters: {
          a!forEach(
            enumerate(local!numYears),
            
            a!queryFilter(
              field: "myDate",
              operator: "=",
              value: date(
                year(today()) - fv!item,
                local!month,
                local!day
              )
            )
          )
        }
      )
    )

    result:

Children
No Data