---
title: "compare(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsdate/compare(_:)"
---

# compare(_:)

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

## Declaration

```swift
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

Return Value If: The receiver and anotherDate are exactly equal to each other, ComparisonResult.orderedSame The receiver is later in time than anotherDate, ComparisonResult.orderedDescending The receiver is earlier in time than anotherDate, ComparisonResult.orderedAscending.

## Discussion

Discussion This method detects sub-second differences between dates. If you want to compare dates with a less fine granularity, use timeIntervalSince(_:) to compare the two dates.

## See Also

### Related Documentation

- [isEqual(_:)](objectivec/nsobjectprotocol/isequal(_:).md)

### Comparing Dates

- [isEqual(to:)](foundation/nsdate/isequal(to:).md)
- [earlierDate(_:)](foundation/nsdate/earlierdate(_:).md)
- [laterDate(_:)](foundation/nsdate/laterdate(_:).md)
