0

I have a unixTimeStamp date value. I have converted it to NSDate:
example :

1582118428 => 2020-02-19 13:20:28 +0000

Works fine. Code where I do converting:

let date = NSDate(timeIntervalSince1970: 1582118428)
let dateTimeNow = NSDate()

Question : How can I compare dates, how to for example print("OK") if date was 5 hours older than dateTimeNow or 10 days older than dateTimeNow?

faris97
  • 402
  • 4
  • 24

1 Answers1

1

You can use it as

extension Date {
  func daysFromToday() -> Int {
    return abs(Calendar.current.dateComponents([.day], from: self, to: Date()).day!)
  }
}

You can call this as

if someDate.daysFromToday() >= 10 {
  // your code
}
sDev
  • 1,463
  • 9
  • 17