WebApi
WebApi copied to clipboard
Support relative date filter query
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 can you try to use the date-related Arithmetic Operators and let us know the result?
@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 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