[Solved] Swift 4 days until date [duplicate]


It would be helpful to see what you’ve tried to give some advice, but nonetheless, you can use NSCalendar’s components to accomplish this.

let calendar = Calendar.current
let startOfDay1 = calendar.startOfDay(for: date1)
let startOfDay2 = calendar.startOfDay(for: date2)
let components = calendar.dateComponents([.day], from: startOfDay1, to: startOfDay2)

You can customize that above to get more specific minutes from your date object.

https://developer.apple.com/documentation/foundation/nscalendar/1407925-components

Edit: For Swift 4, you don’t need to bridge. You can use Calendar directly (edited code above). https://developer.apple.com/documentation/foundation/calendar/2293176-datecomponents

7

solved Swift 4 days until date [duplicate]