<!--
{
  "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/isDate(_:equalTo:toUnitGranularity:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCalendar(im)isDate:equalToDate:toUnitGranularity:"
  },
  "title" : "isDate(_:equalTo:toUnitGranularity:)"
}
-->

# isDate(_:equalTo:toUnitGranularity:)

Indicates whether two dates are equal to a given unit of granularity.

```
func isDate(_ date1: Date, equalTo date2: Date, toUnitGranularity unit: NSCalendar.Unit) -> Bool
```

## Parameters

`date1`

The first date to compare.

`date2`

The second date to compare.

`unit`

The smallest unit that must, along with all larger units, be equal in the given dates. For possible values, see [`NSCalendar.Unit`](/documentation/Foundation/NSCalendar/Unit).

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if both dates have equal date component for all units greater than or equal to the given unit, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

---

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)