4

I have a date1 and the current Date when the view did load. Now I want to display how many days have passed since the day.

let timeInterval = date1.timeIntervalSince(date2)

Now I want to convert the timeInterval in days. Anyone could help?

1 Answers1

10

Rather than using TimeInterval you can get the number of days directly by using the Calendar class and DateComponents

let days = Calendar.current.dateComponents([.day], from: date1, to: date2)
print(days.day!)
Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52