Checking if one NSDate is greater than another

The easiest method i'm aware is:

if( [firstDate timeIntervalSinceDate:secondDate] > 0 ) {

The other answers cover compare:, wanted to add some flavour ;).


To compare dates use -compare: method:

Return Value If:

  • The receiver and anotherDate are exactly equal to each other, NSOrderedSame
  • The receiver is later in time than anotherDate, NSOrderedDescending
  • The receiver is earlier in time than anotherDate, NSOrderedAscending.

What about...

if ([datStartDate earlierDate: datEndDate] == datStartDate) {
    // datStartDate is earlier
} else {
    // datEndDate is earlier
}