how to compare date in swift 3.0?

Ashwin Indianic picture Ashwin Indianic · Feb 17, 2017 · Viewed 13.6k times · Source

I have two dates and I want to compare it. How can I compare dates? I have to date objects. Say modificateionDate older updatedDate.

So which is the best practice to compare dates?

Answer

Nirav D picture Nirav D · Feb 17, 2017

Date now conforms to Comparable protocol. So you can simply use <, > and == to compare two Date type objects.

if modificateionDate < updatedDate {
     //modificateionDate is less than updatedDate
}