Posted By

ggrngg on 10/10/11


Tagged

calendar date dates CALCULATION NSDate


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Tintenklecks
raulestevez


Calendar - difference between two dates


 / Published in: Objective C
 

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

  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);

Report this snippet  

You need to login to post a comment.