-4

I'm trying to build an app that let's you choose a date and then it will show how many days have passed since that date (familiar to "Been Together" on the App Store). I've found a great tutorial on Youtube, the only problem is, my app is coded using Swift, while the tutorial is in Objective-C. I'm wondering if anyone could help me out with a great tutorial or at least an explanation. Thanks!

  • Does this answer your question? [Swift: Compare date by days](https://stackoverflow.com/questions/40633139/swift-compare-date-by-days) – jarmod Aug 06 '21 at 11:27
  • See Help Center to find out what type of questions are acceptable here. – El Tomato Aug 06 '21 at 11:49

1 Answers1

1

You can reach the desired result using this function:

func days(from beginning: Date) -> Int {
    Calendar.current.dateComponents([.day], from: beginning, to: Date()).day!
}
Roma Kavinskyi
  • 268
  • 4
  • 12