Alex Rivera | Logout

Determine the number of months between two dates using Cocoa

Asked 2009-09-28T21:18:38.740
9

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

Thanks, Stan

Edit
Report

2 Answers

38
NSInteger month = [[[NSCalendar currentCalendar] components: NSCalendarUnitMonth
                                                   fromDate: yourFirstDate
                                                     toDate: yourSecondDate
                                                    options: 0] month];
answered 2009-09-29T03:28:49.130
14

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

answered 2009-09-28T21:24:30.350

Your Answer