Reputation: 1423
i am getting date from data base table .I get duedate from database till here all is proper Now i have to compare this duedate with current date if current date is more or equal then duedate which is coming from database then i wany to print string on cell as 'Due'
i try lot but my problem is that the string value showing some ware and they not showing some ware what is the mistack in my code.
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSString* duedate = [dateFormat stringFromDate:taskobject.DueDate];
NSDate *currentdate;
currentdate=[NSDate date];
//NSDateFormatter *dateFormat1 = [[NSDateFormatter alloc] init];
//[dateFormat1 setDateFormat:@"dd/MM/yyyy"];
NSString* duedate1 = [dateFormat stringFromDate:currentdate];
if ([currentdate compare:taskobject.DueDate]!=NSOrderedDescending) {
DateLable.text=@"Due";
DateLable.textColor=[UIColor redColor];
}
else{
DateLable.text=duedate;
DateLable.textColor=[UIColor blackColor];
}
Upvotes: 0
Views: 70
Reputation: 2218
NSComparisonResult result = [currentdate compare: duedate];
if( result == NSOrderedDescending || result==NSOrderedSame) {
// true when the dates are the same or the currentdate is later
} else {
// true when the currentdate is earlier
}
Upvotes: 2
Reputation: 8947
this comparesa two dates and tells if there is the difference of 24 hrs in two dates, timeIntervalSinceDate:lastLoadDate sends the seconds difference.
double interval = [[NSDate date] timeIntervalSinceDate:lastLoadDate];
if (interval > 86400 || interval < -86400 ) {
return YES;
}
else
{
enableButtons = YES;
return NO;
}
in your case it will be
double interval = [dueDate timeIntervalSinceDate:currentDate];
if (interva >=0)
{
DateLable.text=@"Due";
DateLable.textColor=[UIColor redColor];
}
else
{
DateLable.text=duedate;
DateLable.textColor=[UIColor blackColor];
}
Upvotes: 0