Instance Method


Indicates the ordering of two given dates based on their components down to a given unit granularity.


func compare(_ date1: Date, to date2: Date, toUnitGranularity unit: NSCalendar.Unit) -> ComparisonResult



The first date to compare.


The second date to compare.


The smallest unit that must, along with all larger units, be equal for the given dates to be considered the same. For possible values, see NSCalendar.Unit.

Return Value

NSOrderedSame if the dates are the same down to the given granularity, otherwise NSOrderedAscending or NSOrderedDescending.

See Also

Comparing Dates

func isDate(Date, equalTo: Date, toUnitGranularity: NSCalendar.Unit)

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

func isDate(Date, inSameDayAs: Date)

Indicates whether two dates are in the same day.

func isDateInToday(Date)

Indicates whether the given date is in “today.”

func isDateInTomorrow(Date)

Indicates whether the given date is in “tomorrow.”

func isDateInWeekend(Date)

Indicates whether a given date falls within a weekend period, as defined by the calendar and the calendar's locale.

func isDateInYesterday(Date)

Indicates whether the given date is in “yesterday.”