Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your date Format tor u set wrong it`s be dd-MM-yyyy HH:mm:ss . may be that was the problem.. u get wrong date and not get answer i send litte bit code for get day diffrence. <p></p> <pre><code> NSDateFormatter *tempFormatter = [[[NSDateFormatter alloc]init]autorelease]; [tempFormatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"]; NSDate *startdate = [tempFormatter dateFromString:@"15-01-2011 09:00:00"]; NSLog(@"startdate ==%@",startdate); NSDateFormatter *tempFormatter1 = [[[NSDateFormatter alloc]init]autorelease]; [tempFormatter1 setDateFormat:@"dd-MM-yyyy HH:mm:ss"]; NSDate *toDate = [tempFormatter1 dateFromString:@"20-01-2011 09:00:00"]; NSLog(@"toDate ==%@",toDate); int i = [startdate timeIntervalSince1970]; int j = [toDate timeIntervalSince1970]; double X = j-i; int days=(int)((double)X/(3600.0*24.00)); NSLog(@"Total Days Between::%d",days); </code></pre> <hr> <p><strong>Edit 1:</strong></p> <p>we can find date difference using following function :</p> <pre><code>-(int)dateDiffrenceFromDate:(NSString *)date1 second:(NSString *)date2 { // Manage Date Formation same for both dates NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd-MM-yyyy"]; NSDate *startDate = [formatter dateFromString:date1]; NSDate *endDate = [formatter dateFromString:date2]; unsigned flags = NSDayCalendarUnit; NSDateComponents *difference = [[NSCalendar currentCalendar] components:flags fromDate:startDate toDate:endDate options:0]; int dayDiff = [difference day]; return dayDiff; } </code></pre> <p>from Abizern`s ans. find more infromation for NSDateComponent <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateComponents_Class/Reference/Reference.html" rel="nofollow"><strong>here.</strong></a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload