Below code is used to find number of days between two dates
NSDateFormatter *startDateformatter = [[NSDateFormatter alloc]init];
[startDateformatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"];//setting date formate
NSDate *startdate = [startDateformatter dateFromString:@"15-01-2011 09:00:00"]; //initializing from date
NSLog(@"startdate is %@",startdate);
NSDateFormatter *toDateformatter = [[NSDateFormatter alloc]init];
[toDateformatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
NSDate *toDate = [toDateformatter dateFromString:@"25-01-2011 09:00:00"];//initializing to date
NSLog(@"toDate is %@",toDate);
int i = [startdate timeIntervalSince1970];
int j = [toDate timeIntervalSince1970];
double X = j-i;
int days=(int)((double)X/(3600.0*24.00));
NSLog(@"Total Days Between::%d",days);
0 Comment(s)