I have 2 dates in the following format:
August 6, 2012
I am using the following code to attempt to determine which date is later:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMMM d, yyyy"];
NSString *today = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", today);
NSDate *todayDate = [dateFormatter dateFromString:today];
NSLog(@"TodayDate: %@", todayDate);
for (Job *j in appDelegate.jobs){
if ([j.dueDate laterDate:todayDate]){
[jobsToDisplay addObject:j];
}
}
However this code does not work, it seems to return dates that are a day + 1 hour behind what they should be. Can anyone explain what I need to do here?
Thanks a lot,
Tysin
You can use
compare:instance method of NSDateFor more Detail https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html
https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/Reference/reference.html#//apple_ref/doc/c_ref/NSComparisonResult