iphone - Compare two NSDates for same date/time -


this question has answer here:

is date1 == date2 not valid way compare? if not, correct alternative?

here's code:

- (nsdate*) datewithnotime {     unsigned int flags = nsyearcalendarunit | nsmonthcalendarunit | nsdaycalendarunit;     nscalendar* calendar = [nscalendar currentcalendar];     nsdatecomponents* components = [calendar components:flags fromdate:self];     nsdate* dateonly = [calendar datefromcomponents:components];     return dateonly; }  - (bool) samedayasdate:(nsdate*)datetocompare {     nsdate *date1 = [self datewithnotime];     nsdate *date2 = [datetocompare datewithnotime];     return date1 == date2;       // here things seem fail  } 

you're comparing 2 pointer values. need use nsdate comparison method like:

return ([date1 compare:date2] == nsorderedsame); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -