Skip to content

Instantly share code, notes, and snippets.

@OksanaFedorchuk
Created April 27, 2021 08:57
Show Gist options
  • Save OksanaFedorchuk/df6418569fdbe2255049e8b409c9b6f3 to your computer and use it in GitHub Desktop.
Save OksanaFedorchuk/df6418569fdbe2255049e8b409c9b6f3 to your computer and use it in GitHub Desktop.
Extension of Date to calculate days/seconds between two days.
extension Date {
func daysBetweenDates(start: Date, end: Date) -> Int {
let days = Calendar.current.dateComponents([.day], from: start, to: end).day!
let returnDays = days+1
return returnDays
}
func secondsBetweenDates(start: Date, end: Date) -> Int {
let seconds = Calendar.current.dateComponents([.second], from: start, to: end).second!
return seconds
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment