You should really use NSCalendar and NSDateComponents for such calculations, as they can become very complex and can be full of annoying cases.
If you use NSCalendar and NSDateComponents (like the code below), it will take care of all things, such as leap years for you.
NSDate *now = [NSDate date]; NSDateComponents *minusHundredYears = [NSDateComponents new]; minusHundredYears.year = -100; NSDate *hundredYearsAgo = [[NSCalendar currentCalendar] dateByAddingComponents:minusHundredYears toDate:now options:0];
I wrote about working with dates in Objective-C in general, if you need further reading on this.
David Rönnqvist
source share