compare(_:to:toGranularity:)

Compares the given dates down to the given component, reporting them orderedSame if they are the same in the given component and all larger components, otherwise either orderedAscending or orderedDescending.

iOS
8.0+
macOS
10.10+
tvOS
9.0+
watchOS
2.0+
func compare(_ date1: Date, to date2: Date, toGranularity component: Calendar.Component) -> ComparisonResult

Parameters

date1

A date to compare.

date2

A date to compare.

  • parameter: component: A granularity to compare. For example, pass .hour to check if two dates are in the same hour.