<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMotion",
  "identifier" : "/documentation/CoreMotion/CMMotionActivityManager/queryActivityStarting(from:to:to:withHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Motion"
    ],
    "preciseIdentifier" : "c:objc(cs)CMMotionActivityManager(im)queryActivityStartingFromDate:toDate:toQueue:withHandler:"
  },
  "title" : "queryActivityStarting(from:to:to:withHandler:)"
}
-->

# queryActivityStarting(from:to:to:withHandler:)

Gathers and returns historical motion data for the specified time period

```
func queryActivityStarting(from start: Date, to end: Date, to queue: OperationQueue, withHandler handler: @escaping CMMotionActivityQueryHandler)
```

## Parameters

`start`

The start time to use when gathering motion data. This parameter must not be `nil`.

`end`

The end time to use when gathering motion data. This parameter must not be `nil`.

`queue`

The operation queue on which to execute the specified `handler` block. You can specify a custom queue or use the operation queue associated with your app’s main thread. This parameter must not be `nil`.

`handler`

The block to execute with the results. For information about the parameters of this block, see [`CMMotionActivityQueryHandler`](/documentation/CoreMotion/CMMotionActivityQueryHandler). This parameter must not be `nil`.

## Discussion

This method runs asynchronously, returning immediately and delivering the results to the specified `handler` block. A delay of up to several minutes in reported activities is expected.

The system stores only the last seven days worth of activity data at most. If there are no samples for the specified range of time, an error object with the code [`CMErrorUnknown`](/documentation/CoreMotion/CMErrorUnknown) is passed to the `handler` block.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)