Search code examples
datedatetimeodataodata-v4

How to check if date equals date of datetime property only using query parameters


I have a DateTime property.

I want to check if a date is equal to the date in my property and it has to be done purely in the url query parameters available in OData v4.

This doesn't work :(

GET ~/odata/foo$filter=date(myProperty) eq date(1980-01-01)

Yes I can use greater then or equal but that's is already working as intended. It's equal and not equal that's the problem.


Solution

  • From ABNF rules, Date value is a value with format:

    dateValue = year "-" month "-" day

    So, I think you shouldn't add date prefix. That's:

    GET ~/odata/foo$filter=date(myProperty) eq 1980-01-01

    Here's some test cases provided by ODataTeam:

    https://github.com/OData/WebApi/blob/master/OData/test/E2ETest/WebStack.QA.Test.OData/DateAndTimeOfDay/DateAndTimeOfDayTest.cs#L169-L171

    and https://github.com/OData/WebApi/blob/master/OData/test/E2ETest/WebStack.QA.Test.OData/DateAndTimeOfDay/DateAndTimeOfDayTest.cs#L208-L212

    Besides, there's a simple tutorial you can refer to:

    http://odata.github.io/WebApi/#04-04-date-and-timeofday-support

    Thanks. Hope it can help.