I am calculating difference between two dates in my testapp. It works fine if I don't change the month but when i change the month it doesn't work. Please help me here is code I am using:-
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
//[df setDateStyle:NSDateFormatterMediumStyle];
df.dateFormat = @"YYYY-MM-DD";
NSDate *date1 = [df dateFromString:@"2011-04-30"];
NSDate *date2 = [df dateFromString:@"2011-05-03"];
NSLog(@"date1=%@",date1);
NSLog(@"date2=%@",date2);
NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1];
int numberOfDays = secondsBetween / 86400;
NSLog(@"There are %d days in between the two dates.", numberOfDays);
output is -27. I am confuse.
please anyone help me to fix this problem..