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

# compare(_:)

Indicates the temporal ordering of the receiver and another given date.

```
func compare(_ other: Date) -> ComparisonResult
```

## Parameters

`other`

The date with which to compare the receiver.

    This value must not be     `nil`    . If the value is     `nil`    , the behavior is undefined and may change in future versions of macOS.

## Return Value

If:

- The receiver and `anotherDate` are exactly equal to each other, [`ComparisonResult.orderedSame`](/documentation/Foundation/ComparisonResult/orderedSame)
- The receiver is later in time than `anotherDate`, [`ComparisonResult.orderedDescending`](/documentation/Foundation/ComparisonResult/orderedDescending)
- The receiver is earlier in time than `anotherDate`, [`ComparisonResult.orderedAscending`](/documentation/Foundation/ComparisonResult/orderedAscending).

## Discussion

This method detects sub-second differences between dates. If you want to compare dates with a less fine granularity, use [`timeIntervalSince(_:)`](/documentation/Foundation/NSDate/timeIntervalSince(_:)) to compare the two dates.

## See Also

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/isEqual(_:)>



---

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)