I am using the following code to compare two dates, I would expect the code to return "newDate is less" as todays date is 2018-03-16 but instead it is returning both dates are the same. Any way to solve this? I know it must be very simple just can't pin my finger on it.
NSDateFormatter *dateFormatter=[NSDateFormatter new];
NSDate *today = [NSDate date];
NSDate *newDate = [dateFormatter dateFromString:@"2018-03-14"];
if([today compare:newDate]==NSOrderedAscending){
NSLog(@"today is less");
}
else if([today compare:newDate]==NSOrderedDescending){
NSLog(@"newDate is less");
}
else{
NSLog(@"Both dates are same");
}