Instance Method
compare(_:to:toGranularity:)
iOS 8.0+
iPadOS 8.0+
Mac Catalyst 8.0+
macOS 10.10+
tvOS 9.0+
watchOS 2.0+
Compares two dates down to the specified component.
func compare(_ date1: Date, to date2: Date, toGranularity component: Calendar.Component) -> ComparisonResult
Parameters
date1A date to compare.
date2A date to compare.
Discussion
The result is orderedSame if they are the same in the given component and all larger components. Otherwise, the result is either orderedAscending or orderedDescending.
parameter: component: A granularity to compare. For example, pass
.hourto check if two dates are in the same hour.