Calendar - difference between two dates


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. NSDateFormatter *tempFormatter = [[[NSDateFormatter alloc]init]autorelease];
  2. [tempFormatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
  3. NSDate *startdate = [tempFormatter dateFromString:@"15-01-2011 09:00:00"];
  4. NSLog(@"startdate ==%@",startdate);
  5.  
  6. NSDateFormatter *tempFormatter1 = [[[NSDateFormatter alloc]init]autorelease];
  7. [tempFormatter1 setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
  8. NSDate *toDate = [tempFormatter1 dateFromString:@"20-01-2011 09:00:00"];
  9. NSLog(@"toDate ==%@",toDate);
  10.  
  11. int i = [startdate timeIntervalSince1970];
  12. int j = [toDate timeIntervalSince1970];
  13.  
  14. double X = j-i;
  15.  
  16. int days=(int)((double)X/(3600.0*24.00));
  17. NSLog(@"Total Days Between::%d",days);

URL: http://stackoverflow.com/questions/6069480/find-total-number-of-days-between-two-dates-in-iphone

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.