Created
April 27, 2021 08:57
-
-
Save OksanaFedorchuk/df6418569fdbe2255049e8b409c9b6f3 to your computer and use it in GitHub Desktop.
Extension of Date to calculate days/seconds between two days.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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