Help, please, make a function on Swift that returns the difference in days between two dates.
func dateDiff (pastDate: Date, nowDate: Date) -> Int { ... return ... } Incoming type may not be a Date .
Thank.
Help, please, make a function on Swift that returns the difference in days between two dates.
func dateDiff (pastDate: Date, nowDate: Date) -> Int { ... return ... } Incoming type may not be a Date .
Thank.
You can get the difference between dates:
let dateDiff = Calendar.current.dateComponents([.day], from: date1, to: date2).day You can arrange in the form of an extension to the Date :
extension Date { func days(to secondDate: Date, calendar: Calendar = Calendar.current) -> Int { return calendar.dateComponents([.day], from: self, to: secondDate).day! // Здесь force unwrap, так как в компонентах указали .day и берем day } } let dateDiff = date1.days(to: date2) Source: https://ru.stackoverflow.com/questions/712922/
All Articles