Hi hope someone can help me. I need to calculate the days between to dates. The flow are:
- Pick a date
- New date by years (ex. 2 years)
- Get the days between the "pick date" and the "New date"
Hi hope someone can help me. I need to calculate the days between to dates. The flow are:
Try this code, updated for Swift 2.0
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let first = "2010-09-01"
let firstDate = dateFormatter.dateFromString(first)!
let last = "2010-09-05"
let lastDate = dateFormatter.dateFromString(last)!
let currentCalendar = NSCalendar.currentCalendar()
let timeUnitDay = NSCalendarUnit.Day
let daysBetween = currentCalendar.components(timeUnitDay, fromDate: firstDate, toDate: lastDate, options: NSCalendarOptions.MatchStrictly)
print(daysBetween.day)