This project is read-only.

WCF Web API Filter breaks with DateTimeOffset value


I enabled OData queries by defining an IQueryable method and tested by using ‘$filter=Id eq 1’ which worked fine.
However when trying to filter by passing a DateTimeOffset value I get the following error message:

$filter=LastModifiedDate ge datetimeoffset('2011-06-01T14:03:00+00:00Z')
Error = Microsoft.ApplicationServer.Query.ParseException: A value of type 'String' cannot be converted to type 'DateTimeOffset'

I have also tried using the following URI's incase I was doing something wrong.
$filter=LastModifiedDate ge (datetimeoffset'2011-06-01T14:03:00+00:00Z')
$filter=LastModifiedDate ge datetimeoffset'2011-06-01T14:03:00+00:00Z'

However I get the following errors respectively:
Microsoft.ApplicationServer.Query.ParseException: Syntax error
Microsoft.ApplicationServer.Query.ParseException: '.' or '(' expected


lybax wrote May 13, 2014 at 2:22 PM

I had the same issue and finally noticed that the '+' character was simply interpreted as a space (URL syntax), as explained in odata.error:
"Unrecognized 'Edm.DateTimeOffset' literal datetimeOffset'2014-05-12T16:35:20 2:00'"

To overcome this issue, you need to URL encode '+' character ('%2B'):

Z ('Zulu' in military/aviation) is part of the ISO 8601 datetime standard for UTC times, and is therefore only "needed" if provided datetime is in UTC.