public func getDateBeforeYear(year : Int) -> Date{
    let gregorian: NSCalendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)!
    let currentDate: Date = Date()
    let components: NSDateComponents = NSDateComponents()
    
    components.year = -year
    return gregorian.date(byAdding: components as DateComponents, to: currentDate, options: NSCalendar.Options(rawValue: 0))!
}

You may also like

Leave a Reply