views:

219

answers:

2

Hello,

How do I calculate the number of months between two dates using Cocoa?

Thanks, Stan

+8  A: 

Look at NSCalendars components:fromDate:toDate:options method. It allows you to subtract dates and then extract the months property value

ennuikiller
+1  A: 
NSInteger month = [[[NSCalendar currentCalendar] components: NSMonthCalendarUnit
                                                   fromDate: yourFirstDate
                                                     toDate: yourSecondDate
                                                    options: 0] month];
Exactly what I needed - thanks.
Smendrick