By default [NSDate date]
return date in like 2013-08-06 08:50:25 +0000
and you have set your formatter to yyyy-MM-dd
this, so you have to convert your startDate to yyyy-MM-dd
this form..
Try this
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-ddHH:mm:ss ZZZ"];
NSDate *startDate = [NSDate date];
NSLog(@"%@",startDate);
NSDate *endDate = [f dateFromString:end];
NSLog(@"%@",endDate);
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorianCalendar components:NSDayCalendarUnit
fromDate:startDate
toDate:endDate
options:0];
return components.day;