Thursday, March 27, 2014

Compare NSDate instances


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  NSComparisonResult result = [date1 compare:date2];  
  if (result == NSOrderedAscending)
  {
    // date1 < date2
  }
  else if (result == NSOrderedDescending)
  {
    // date1 > date2
  }
  else
  {
    // date1 == date2
  }

or

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  if ([date1 timeIntervalSinceReferenceDate] < [date2 timeIntervalSinceReferenceDate])
  {
    // date1 < date2
  }
  else if ([date1 timeIntervalSinceReferenceDate] > [date2 timeIntervalSinceReferenceDate])
  {
    // date1 > date2
  }
  else
  {
    // date1 == date2
  }

Refs
http://stackoverflow.com/questions/5965044/how-to-compare-two-nsdates-which-is-more-recent

No comments:

Post a Comment