Reputation: 23
I'm trying to get data in between the dates 2020-04-01 and 2021-03-31. I tried the query posted below but I got data from earlier than 2020-04-01.
Is my query wrong? I expect to get data exactly between 2020-04-01 and 2021-03-31.
/odata/v2/EmpJob?$format=json&fromDate=2020-04-01&toDate=2021-03-31
I changed entities, queries, and so on, but no luck.
Upvotes: 1
Views: 3400
Reputation: 377
One would think that it would indeed be as simple as that. However: https://userapps.support.sap.com/sap/support/knowledge/en/2920680
It seems that the 2 conditions are seen separately instead of a combined filter.
Cause This is expected behavior. In short: it is not possible to combine two 'lastModifiedDateTime' filters to represent a time interval. Even if it seems to make sense semantically, the API will not interpret it as a range. The key idea to understand this is that the 'lastModifiedDateTime' filter looks at all the effective dated records of an employee as one object of analysis.
Although the query's semantic structure suggests the following logic:
IF ANY of the employee's records has 'lastModifiedDateTim' greater than provided date AND lesser than the other provided date, return true.
The actual logic is as below:
IF ANY of the employee's records has 'lastModifiedDateTime' greater than provided date AND ANY of the employee's records has 'lastModifiedDateTime' lesser than the other provided date, return true.
So, for all the records related to a specific user, it can find one whose LMD>2020-04-21T07:38:00Z and it can find another one whose LMD<2020-04-21T08:38:00Z.
Which record(s) are returned will be determined by the 'asOfDate' or 'fromDate' and 'toDate' parameters you are passing to the query. If none of there parameters are being passed (as is the case for the query used as example in this KBA), the query implicitly passes 'asOfDate'=today and the employee's current active record is returned. See Effective Dating Query in OData for more information.
Upvotes: 1