<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKQuery/predicateForSamples(withStart:end:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKQuery(cm)predicateForSamplesWithStartDate:endDate:options:"
  },
  "title" : "predicateForSamples(withStart:end:options:)"
}
-->

# predicateForSamples(withStart:end:options:)

Returns a predicate for samples whose start and end dates fall within the specified time interval.

```
class func predicateForSamples(withStart startDate: Date?, end endDate: Date?, options: HKQueryOptions = []) -> NSPredicate
```

## Parameters

`startDate`

The start date for the target time interval.

`endDate`

The end date for the target time interval.

`options`

A constant that specifies how the sample’s start and end date are compared with the target time interval. For a list of possible values, see [`HKQueryOptions`](/documentation/HealthKit/HKQueryOptions).

## Return Value

A predicate for samples whose start and end dates fall within the specified time interval. This predicate works only with samples.

## Discussion

Use this convenience method to create a predicate that compares a sample’s start and end dates with a specified time interval. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

```objc
NSPredicate *timeInterval =
[HKQuery predicateForSamplesWithStartDate:myStartDate
                                  endDate:myEndDate
                                  options:HKQueryOptionNone];
 
NSPredicate *explicitTimeInterval =
[NSPredicate predicateWithFormat:@"%K >= %@ AND %K < %@",
 HKPredicateKeyPathEndDate, myStartDate,
 HKPredicateKeyPathStartDate, myEndDate];
```

## See Also

[`HKPredicateKeyPathEndDate`](/documentation/HealthKit/HKPredicateKeyPathEndDate)

The key path for accessing the sample’s end date.

[`HKPredicateKeyPathStartDate`](/documentation/HealthKit/HKPredicateKeyPathStartDate)

The key path for accessing the sample’s start date.

[`endDate`](/documentation/HealthKit/HKSample/endDate)

The sample’s end date.

[`startDate`](/documentation/HealthKit/HKSample/startDate)

The sample’s start date.



---

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)