chax-at / prisma-filter

MIT License
38 stars 8 forks source link

Filter by Date Only #7

Closed EugeneGohh closed 1 year ago

EugeneGohh commented 1 year ago

The object response:

 "createdAt": "2023-05-30T08:43:55.052Z",

Are there any workarounds where I only want to filter by date only (exclude time)? Meaning only filter by 2023-05-30.

Valerionn commented 1 year ago

The filter string gets directly transferred to Prisma, therefore you should be able to simply use the date as a string directly, e.g.:

const filterBuilder = new FilterBuilder<User>()
  .addFilter('createdAt', FilterOperationType.gte, '2023-05-30');
const filter = filterBuilder.toFilter();
const queryString = filterBuilder.toQueryString();

I don't know how Prisma handles those filters by date exactly, but alternatively if you only want a single day, you can also just filter using gte: '2023-05-30T00:00:00.000Z' and lt: '2023-05-31T00:00:00.000Z' as well if the example above doesn't work for this.