Add days to my existing date iOS swift

 Problem:

I had one date with me.I want to add some days to the date and get the new date.

Solution:

extension Date {

    func addDays(daysAdd: Int) -> Date {

        let secondsInDays: TimeInterval = Double(daysToAdd) * 60 * 60 * 24

        let dateWithDaysAdded: Date = self.addingTimeInterval(secondsInDays)

        //Return Result

        return dateWithDaysAdded

    }

}



Call the above function as like below.


let newDate = yourdate.addDays(1)



newDate will store the new date after appending one day.

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift