You can use the link
According to Apple NSDate documentation, compare:
Returns an NSComparisonResult value that indicates the temporal ordering of the receiver and another given date. - (NSComparisonResult)compare:(NSDate *)anotherDate Parameters anotherDate The date with which to compare the receiver. This value must not be nil. If the value is nil, the behavior is undefined and may change in future versions of Mac OS X. 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
In other words:
if ([date1 compare:date2]==NSOrderedSame) ...
Please note that it would be easier to read and write this:
if ([date2 isEqualToDate:date2]) ...
See Apple Documentation about this. If you feel any problem, you can also use this link here . Here you can find the answer of Nelson Brian.
I did this at my end as follows:
NSDate * currentDateObj=@ "firstDate"; NSDate * shiftDateFieldObj=@ "SecondDate"; NSTimeInterval timeDifferenceBetweenDates = [shiftDateFieldObj timeIntervalSinceDate:currentDateObj];
You can also get the time interval according to the time difference between the dates. Hope this helps.
iEinstein
source share