frameworks โฉ Foundation โฉ Calendar
Sarun โฉ Getting the number of days between two dates in Swift
Getting UIKit's UICalendarView from iOS 16 fully functioning in a SwiftUI app
import Foundation // Calendar extension Calendar { // Calendar.current.numberOfDays(between: date1, and: date2) public func numberOfDays(between date1: Date, and date2: Date) -> Int { let date1 = startOfDay(for: date1) let date2 = startOfDay(for: date2) let components = dateComponents([.day], from: date1, to: date2) return components.day! } }
Calendar
DatePicker
Date
Last updated 3 years ago
Was this helpful?