Correct Predicate to get daily steps data AS calculated by the health app

I have written two difference types of predicates and both give me different results as compared to the health app. I am sure this has something to do with 12am, around when I take a little walk.

Here are the two predicates...
Code Block
 NSPredicate *daySearchPredicate = [NSPredicate predicateWithFormat:@"startDate>=%@ && startDate<%@ && endDate>=%@ && endDate<%@",historyDate,nextDate,historyDate,nextDate];
Code Block
NSPredicate *daySearchPredicate = [NSPredicate predicateWithFormat:@"startDate>=%@ && startDate<%@",historyDate,nextDate];

The data in the health app is ...
Yesterday: 1714
Today: 1076

The data I get with the first predicate is...
Yesterday: 1559
Today: 917

with the second predicate is...
Yesterday: 1874
Today: 917

Note: They even don't total up to be the same as each other or the health app data.

Here is my code that calculates the total...
Code Block
//calculate total steps for today
int64_t steps=0;
for (HKQuantitySample *stepsSample in stepsPredicateResultsArray)
  {
    HKQuantity *stepsQuantity = [stepsSample quantity];
    int64_t currentSampleSteps = (int64_t)[stepsQuantity doubleValueForUnit:[HKUnit countUnit]];
    steps = steps + currentSampleSteps;
  }
  hObject.steps=steps;

Please help me set a predicate which make the Health app data and my data to be the same.

Thanks.



I found a method in HKQuery abstract class and I tried all the three combinations of Options but it gives me different results each time...
Code Block
NSPredicate *daySearchPredicate = [HKQuery predicateForSamplesWithStartDate:historyDate endDate:historyDate options:HKQueryOptionNone];

In Short, I want a predicate that searches the stepsSampleArray for steps from 00:00:00hrs current date to 11:59:59 hrs current date.
does no one know the solution?

@ace.neerav did you found any solution? I am facing the same issue, if the sample time range has the midnight in it, it's giving incorrect value, rest all day, the steps are exactly matching the Health App.

Correct Predicate to get daily steps data AS calculated by the health app
 
 
Q