WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Support relative date filter query

Open komdil opened this issue 2 years ago • 3 comments

I am using OData. And I have lots of scenarios in that I need to do a filter using relative date.

Assemblies affected

It is related to all versions I guess

Reproduce steps

Scenarios: I have a Transaction entity with Date property and let's say I need to get transactions of last: 10 days 6 month 2 years .......

So I want to make a queries something like: .../Transaction?$filter=Date lt now().AddDay(-10) .../Transaction?$filter=Date lt now().AddMonth(-6) .../Transaction?$filter=Date lt now().AddYear(-2)

Expected result

I would like to have some kind of query to filter my transactions based on a relative date

Actual result

Currently, OData does not support it

komdil avatar Jun 06 '22 13:06 komdil

@komdil can you try to use the date-related Arithmetic Operators and let us know the result?

xuzhg avatar Jun 14 '22 16:06 xuzhg

@komdil can you try to use the date-related Arithmetic Operators and let us know the result?

@xuzhg Can you show any examples for solving my problem above?

komdil avatar Jun 15 '22 03:06 komdil

@komdil Look at the tests from this line https://github.com/OData/odata.net/blob/370cd96aa2a78aecff1b7f9ebe9bebaa7c25ab81/test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/FilterAndOrderByFunctionalTests.cs#L1619

KenitoInc avatar Nov 20 '22 10:11 KenitoInc