I am trying to query my OData service for a data with a datetime greater or equal to given value. It is not working as expected
I have read the documentation:
https://docs.microsoft.com/en-us/odata/webapi/datetime-support#filter-datetime
Assemblies:
- Microsoft.AspNetCore.OData 7.4.0
- NET Core 3
- EF Core
Reproduce steps
I have tried the following query formats:
https://myurl/api/resource?$filter=city eq 'Kigali' and purchaseDateTime gt 2020-01-01T23:59:59.99Z &$orderby=purchaseDateTime desc
HTTP 500 - Conversion failed when converting date and/or time from character string.https://myurl/api/resource?$filter=city eq 'Kigali' and purchaseDateTime gt cast(2020-01-01T23:59:59.99Z,Edm.DateTimeOffset) &$orderby=purchaseDateTime desc
returns HTTP 500 - Internal Server Errorhttps://myurl/api/resource?$filter=city eq 'Kigali' and purchaseDateTime gt datetime'2020-01-01T23:59:59.99Z' &$orderby=purchaseDateTime desc
On the OData site, this works
Expected result
Return the data according to the query in the same way that the the http://services.odata.org responds
Actual results
HTTP Bad Request or HTTP 500
Microsoft says this should work:
GET ~/Customers?$filter=Birthday lt cast(2015-04-01T04:11:31%2B08:00,Edm.DateTimeOffset)
GET ~/Customers?$filter=year(Birthday) eq 2010
Other sources of info I have tried:
https://myurl/api/resource
? I tested your queries and it works for me. – Michael Wang