Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to find number of days between two dates

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 419
    Comment on it

    Below code is used to find number of days between two dates

      
        NSDateFormatter *startDateformatter = [[NSDateFormatter alloc]init];
        [startDateformatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"];//setting date formate
        NSDate *startdate = [startDateformatter dateFromString:@"15-01-2011 09:00:00"]; //initializing from date
        NSLog(@"startdate is %@",startdate);
        
        NSDateFormatter *toDateformatter = [[NSDateFormatter alloc]init];
        [toDateformatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
        NSDate *toDate = [toDateformatter dateFromString:@"25-01-2011 09:00:00"];//initializing to date
        NSLog(@"toDate  is %@",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);

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: