---
title: "predicateForSamples(withStart:end:options:)"
framework: healthkit
role: symbol
role_heading: Type Method
path: "healthkit/hkquery/predicateforsamples(withstart:end:options:)"
---

# predicateForSamples(withStart:end:options:)

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

## Declaration

```swift
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 doc://com.apple.healthkit/documentation/HealthKit/HKQueryOptions.

## Return Value

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

## Discussion

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.

## See Also

### Related Documentation

- [HKPredicateKeyPathEndDate](healthkit/hkpredicatekeypathenddate.md)
- [HKPredicateKeyPathStartDate](healthkit/hkpredicatekeypathstartdate.md)
- [endDate](healthkit/hksample/enddate.md)
- [startDate](healthkit/hksample/startdate.md)

### Creating sample predicates

- [HKQueryOptions](healthkit/hkqueryoptions.md)
