I want to compare two dates and do something when one is less or equal than the other, I tried to do it this way:
if ([self.system.systemInbetriebnahme compare:date] == NSOrderedDescending)
return nil;
But this removes the case when they are both equal is there a way to compare dates with >=
?
Thank you
More details: I have a date taken from a double dimension array, and i have a date stored in core data(through date picker), and i go through a loop to compare the two dates with the rule that: Date in array must be greater or equal than input date stored in database.
Latest Edit:
I import a csv file which after parsing and formatting gives me two rows(one for number value and one for dates). Here I am interested in dates.
I store all these in an array and save after checking consistency of the data in this function:
for (NSArray * row in array) { // Handle import if there are at least two rows if (row.count > 1) { dispatch_sync(dispatch_get_main_queue(), ^{ // Try to import value,date formatted row double value = [row[0] doubleValue]; NSDate * date = [dateFormatter dateFromString:row[1]]; //else { // Try to import date,value row if (date && value != 0.0) { [self addReading:value forDate:date]; }
In here i call the function
addreading
to check for errors for some rules and if everything is okey then i save the managedObject Context.if ([installationdatum compare:date] != NSOrderedAscending) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"installation date is bigger than data" delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil] [alert show]; return nil; } else { //Do nothing }
One rule for me is to get the first row element in the array and compare its date with an input stored already in the database which is the
self.system.systemInbetriebnahme
After all this I list all the resulting array in a tableview, though value matching
NSOrderedSame
is never shown when it is equal toself.system.systemInbetriebnahme