How to compare two dates in Swift 3? I found many solutions for other versions of Swift, but they do not work for me.
let clickedDay:String = currentcell.DayLabel.text! let currentDate = NSDate() let currentDay = "" //want the current day let dateFormatter = DateFormatter() var dateAsString = "" if Int(clickedDay)! < 10 { dateAsString = "0" + clickedDay + "-11-2016 GMT" } else { dateAsString = clickedDay + "-11-2016 GMT" } dateFormatter.dateFormat = "dd-MM-yyyy zzz" let clickedDate = dateFormatter.date(from: dateAsString) if currentDate as Date >= clickedDate! as Date { return true } else { //Want to get the days between the currentDate and clickedDate let daysLeft = "" }
I am comparing tow dates, but I need days that are between these tow dates. Can someone help me pls? Thanks and welcome
Added: If I have a date 11/22/2016 and currentdate (now 11/18/2016), I need days between them (in this case 4)
xcode swift swift3 nsdate date-comparison
MMbach
source share