<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCalendar/date(_:matchesComponents:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCalendar(im)date:matchesComponents:"
  },
  "title" : "date(_:matchesComponents:)"
}
-->

# date(_:matchesComponents:)

Returns whether a given date matches all of the given date components.

```
func date(_ date: Date, matchesComponents components: DateComponents) -> Bool
```

## Parameters

`date`

The date for which to perform the calculation.

`components`

The date components to match.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the given date matches the given components, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

This method is useful for determining whether dates calculated by methods like  [`nextDate(after:matching:value:options:)`](/documentation/Foundation/NSCalendar/nextDate(after:matching:value:options:)) or [`enumerateDates(startingAfter:matching:options:using:)`](/documentation/Foundation/NSCalendar/enumerateDates(startingAfter:matching:options:using:)) are exact, or required an adjustment due to a nonexistent time.

## See Also

[`nextDate(after:matching:value:options:)`](/documentation/Foundation/NSCalendar/nextDate(after:matching:value:options:))

Returns the next date after a given date matching the given calendar unit value.

[`enumerateDates(startingAfter:matching:options:using:)`](/documentation/Foundation/NSCalendar/enumerateDates(startingAfter:matching:options:using:))

Computes the dates that match (or most closely match) a given set of components, and calls the block once for each of them, until the enumeration is stopped.



---

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)