Query by month or by year or by specific day

For that, you should use gt/gte and lt/lte filters.

Getting data only for January 2020
http://localhost:1337/users?created_at_gte=2020-01-01&created_at_lte=2020-01-31

Get data for 2020:

http://localhost:1337/users?created_at_gte=2020-01-01&created_at_lte=2020-12-31

As you already learned from above examples, these are date ranges.

Note: You should use only valid dates! Otherwise, you will get errors. For example, you can’t use 2020-02-31 (31 February) as it doesn’t exist.

To get first date of the month and the last one, you can use momentjs’s startOf('month') and endOf('month') functions.

1 Like