I am comparing two dates in this way:
NSDateFormatter *df= [[NSDateFormatter alloc] init];
[df setDateFormat:@" dd : MM : yyyy"];
NSDate *dt1 = [[NSDate alloc] init];
dt1=[df dateFromString:TheDate];
NSDate *Date=[NSDate date];
NSLog (@"DATE CURRENT: %@ DATE 2 %@", Date, dt1);
if ([Date compare:dt1] == NSOrderedDescending) {
NSLog(@"Date is later than date2");
} else if ([Date compare:dt1] == NSOrderedAscending) {
NSLog(@"Date is earlier than date2");
[postsToBeDeleted addObject: textmessage];
} else {
NSLog(@"dates are the same");
}
The NSLog gives me:
DATE CURRENT: 2013-02-05 21:37:54 +0000 DATE 2 2012-01-04 23:00:00 +0000
But it is absolutely clear that the current date is far ahead of the dt1 date, and still I get NSLog(@"Date is later than date2");. Why is this?