I\'m trying to compare two days of NSDate objects, I used at the first time NSDateComponents to calculate difference between my two dates Objects, but it is working correct
For Swift 3:
Expanding from @masa's answer:
extension Calendar {
func daysWithinEraFromDate(startDate: Date, endDate: Date) -> Int? {
guard let startDay = ordinality(of: .day, in: .era, for: startDate) else {
return nil
}
guard let endDay = ordinality(of: .day, in: .era, for: endDate) else {
return nil
}
return endDay - startDay
}
}