GroupBy Day and not by Date

Hello everyone,

I am trying to groupBy date a Query. The things is that date is very precise here, I wanted to know the way to trim the date to get only the YYYY-MM-DD, because I want my array being grouped by day.
Could someone help me ?

Would be grateful. Thanks a lot !!

query {
  refundRequestsList(groupBy: {
    query: {
      createdAt: {
        as: "date"
      }
      _group: {
        as:"refunds"
      }
    }
  }){
    groups{
      date: String
      refunds: RefundRequestGroup
      {
        items{
          id
        }
      }
    }
  }
}

Hello @ronan, to group by a date need to use a specific function that 8base expose for this cases: datePart you can use different options of that field to group by a date, in your case I can recommend you DATE that format in the way that you need (by days):

Example of a real implementation:

query {
  donations(
    groupBy: {
      query: {
        createdAt: { as: "date", fn: { datePart: DATE } }
        amount: { as: "amount", fn: { aggregate: SUM } }
        id: { as: "count", fn: { aggregate: COUNT } }
      }
    }
  ) {
    groups {
      date: Date
      amount: Float
      count: Int
    }
  }
}

Let me know if that help or need another option :wink:

2 Likes