NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@\"MM/dd/yyyy\"];
NSLog([@\"today is \" stringBy
Use if ([date1 isEqualToDate:date2])
for comparing two dates or else you can use the following,
if ([date1 compare:date2] == NSOrderedSame)
if ([date1 compare:date2] == NSOrderedAscending)
if ([date1 compare:date2] == NSOrderedDescending)
>
, <
or =
are only for comparing non-pointers. Basically my understanding is that when you are using these operators, it might be comparing the memory addresses rather than the values in it. So you will get unexpected results.
Logically, this is how it works:
if (obj1 > obj2) {
return NSOrderedDescending;
}
if (obj1 < obj2) {
return NSOrderedAscending;
}
if (obj1 == obj2) {
return NSOrderedSame;
}
You can use any of the compare statements to compare dates.