Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Office 365 Graph API - Greater Than Filter on Received Date

I'm trying to perform a query on the Office 365 Graph API to say "give me all emails before {someISODateTimeString}"

For example:

https://graph.microsoft.com/v1.0/me/messages?$filter=receivedDateTime gt 2016-02-26T14:41:08Z

It would seem that gt (greater than) is actually operating as greater than or equal to (ge), as the above query returns me an email which has the exact receivedDateTime value that I passed into the query.

So I tried a workaround:

https://graph.microsoft.com/v1.0/me/messages?$filter=receivedDateTime ne 2016-02-26T14:41:08Z AND receivedDateTime ge 2016-02-26T14:41:08Z

This also fails to omit the email with the received date of 2016-02-26T14:41:08Z.

Any help with how to achieve a "greater than" query on received date would be appreciated.

like image 583
David de-Vilder Avatar asked Mar 01 '16 17:03

David de-Vilder


1 Answers

The behavior you're seeing is actually due to a loss in precision in the REST APIs. Most date fields (including receivedDateTime) are actually stored with more precision than second. What's happening currently is that your request is being translated to a query where the receivedDateTime > 14:41:08.0000. Messages that appeared at 14:41:08.01 are technically greater than that, even though the precision is lopped off making it appear equal.

The work-around you can use (and one we are internally also looking to apply in all "gt" or "lt" scenarios) is to use "ge" for the next unit, so in your example:

https://graph.microsoft.com/v1.0/me/messages?$filter=receivedDateTime ge 2016-02-26T14:41:09Z
like image 117
Jeff Wight Avatar answered Nov 05 '22 22:11

Jeff Wight