json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Filter by date range

Open avxkim opened this issue 6 years ago • 8 comments

Is it possible filter by date range? I have 2 fields from_date and to_date, is there any way to filter by range?

avxkim avatar Sep 13 '18 10:09 avxkim

Is it possible filter by date range? I have 2 fields from_date and to_date, is there any way to filter by range?

Yes, you can use: dateFieldName_gte and dateFieldName_lte Enjoy!

realtica avatar Apr 17 '19 22:04 realtica

This only works for intersection. Meaning from_date =< to_date. dates from 2017 up to 2018. I am not sure if json-server support cases where you want to exclude a date range. Meaning all dates not in from_date to to_date. ex. dates up to 2017 or dates bigger then 2018.

elpddev avatar Aug 11 '19 07:08 elpddev

Whats the date format to use for filter?

felizardo-felipe avatar Aug 30 '19 18:08 felizardo-felipe

gte and lte is not working on date filter I am want to find data between 24/08/2008 to 24/08/2012 so for between it is not working it is working for equal only any solution please

ladaniavadh avatar Apr 15 '20 05:04 ladaniavadh

@ladaniavadh You'll need to store your date in ISO 8601 format (e.g. "YYYY-MM-DD...") in order to be able to sort and filter properly.

This is standard practice for many reasons, including that it allows simple lexical sorting, and avoids issues with localised date formats.

ciw1973 avatar Apr 22 '20 09:04 ciw1973

@ciw1973 @realtica Is it possible to filter my month in json-server ? if yes then which format to use?

whoafridi avatar Sep 24 '23 05:09 whoafridi

Is it possible filter by date range? I have 2 fields from_date and to_date, is there any way to filter by range?

Yes, you can use: dateFieldName_gte and dateFieldName_lte Enjoy!

Doesn't work for me on dates.

matronator avatar Mar 11 '24 11:03 matronator

Is it possible filter by date range? I have 2 fields from_date and to_date, is there any way to filter by range?

Yes, you can use: dateFieldName_gte and dateFieldName_lte Enjoy!

and initialize the dateFieldName_gte property and dateFieldName_lte property by undefined instead of an empty string, by setting the value equal to undefined, the query will not include that property, which allows you to get data when you don't select the date.

Thanks

ilyassouK avatar Mar 15 '24 08:03 ilyassouK