How can I compare two dates, return a number of days.
Posted
by Dans Eduardo
on Stack Overflow
See other posts from Stack Overflow
or by Dans Eduardo
Published on 2010-03-30T19:18:53Z
Indexed on
2010/03/30
19:23 UTC
Read the original article
Hit count: 165
Hi, how can I compare two dates return number of days. Ex: Missing X days of the Cup. look my code.
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"d MMMM,yyyy"];
NSDate *date1 = [df dateFromString:@"11-05-2010"];
NSDate *date2 = [df dateFromString:@"11-06-2010"];
NSTimeInterval interval = [date2 timeIntervalSinceDate:date1];
//int days = (int)interval / 30;
//int months = (interval - (months/30)) / 30;
NSString *timeDiff = [NSString stringWithFormat:@"%dMissing%d days of the Cup",date1,date2, fabs(interval)];
label.text = timeDiff; // output (Missing X days of the Cup)
© Stack Overflow or respective owner