I am having a mutable array in that array i am having only past date, current date & future date. I have to separate the future date & store into another array. Can you help me.
This is my array:
uniqueItems(
"2015-03-01",
"2015-02-28",
"2015-02-22",
"2015-02-21",
"2015-02-20",
"2015-02-15",
"2015-02-14",
"2015-02-13",
"2015-02-08",
"2015-02-07",
"2015-02-01",
"2015-01-31",
"2015-01-30",
"2015-01-25",
"2015-01-24",
"2015-01-18",
"2015-01-17",
"2015-01-16",
"2015-01-11",
"2015-01-10",
"2014-12-07"
I have tried this coding, but is not working.
NSDate *currentDate = [NSDate date];
NSDate* dateAdded=(NSDate*)[uniqueItems objectAtIndex:0];
double min = [currentDate timeIntervalSinceDate:dateAdded];
int minIndex = 0;
for (int i = 1; i < [uniqueItems count]; ++i)
{
double currentmin = [currentDate timeIntervalSinceDate:[uniqueItems objectAtIndex:i]];
if (currentmin < min) {
min = currentmin;
minIndex = i;}}
you can use NSPredicate block for that. your array does not contain NSDate objects so we need to convert it into NSDate and then compare with [NSDate date]
NSPredicate *findFutureDates = [NSPredicate predicateWithBlock: ^BOOL(id obj, NSDictionary *bind){
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:#"yyyy-MM-dd"];
[df setTimeZone:[NSTimeZone systemTimeZone]];
NSDate *dd = [df dateFromString:(NSString *)obj ];
return ([[NSDate date] compare:dd] == NSOrderedAscending);
}];
NSArray *arrFutureDates = [yourArray filteredArrayUsingPredicate: findFutureDates];
NSLog(#"%#",arrFutureDates);
if you pass NSOrderedAscending will give you future dates if you pass NSOrderedDescending will give you past dates.
NSDate *currentDate = [NSDate date];
NSDate *date;
int offset = 0;
NSMutableArray *futureArray = [[NSMutableArray alloc] init];
for (int i = 1; i < [uniqueItems count]; ++i)
{
date = [uniqueItems objectAtIndex:i];//TODO: Convert to NSDate
offset = [currentDate timeIntervalSinceDate:date];
if (offset < 0) {
[futureArray addObject:[uniqueItems objectAtIndex:i]];
}
}
This is a idea. Sorry, I'm coding in notepad without test.
Your array is of string format not an NSDate object. You can convert a string to nsdate
NSString *dateString = #"2010-02-13";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:dateString];
and then you could do your check.
Related
I have got 6 objects in array of Time
NSMutableArray *time=[[NSMutableArray alloc]initwithObjects:12:30, 14:40, 16:50, 20:30, 21:49, 23:12,nil];
Current time = 17:12;
How should I calculate the nearest time with 8:12 from time_array ?
conclusion must be 20:30
I implemented many formula's like picking up the least value available after substracting the times but there is bugs in it and its not a perfect solution.
Can any one share there idea's to calculate the perfect nearest time in Objective C?
I have tried this
//// Calculating to fetch nearest time
NSDateFormatter *current_time_format = [[NSDateFormatter alloc] init];
[current_time_format setTimeZone:zone];
[current_time_format setDateFormat:#"HHmm"];
NSString *current_date_string=[current_time_format stringFromDate:[NSDate date]];
int current_time_int=[current_date_string intValue];
int nearest_time=10000;
int time_calculation=0;
if ([calculated_time_array count]>=6) {
[calculated_time_array removeAllObjects];
}
for (int i=0; i<[current_timings_array count]; i++) {
NSString *prayer_timings=[current_timings_array objectAtIndex:i];
prayer_timings=[prayer_timings stringByReplacingOccurrencesOfString:#":" withString:#""];
time_calculation=[prayer_timings intValue]-current_time_int;
NSLog(#"%d-%d=%d",[prayer_timings intValue],current_time_int,time_calculation);
NSString *length_value=[NSString stringWithFormat:#"%d",current_time_int];
NSLog(#"lenght_value= %d",[length_value length]);
[calculated_time_array addObject:[NSString stringWithFormat:#"%d",time_calculation]];
if (time_calculation<nearest_time && time_calculation>0) {
nearest_time=time_calculation;
}
NSString *time_string=[NSString stringWithFormat:#"%d",nearest_time];
int index=[calculated_time_array indexOfObject:time_string];
header_bg_image.image=[UIImage imageNamed:[NSString stringWithFormat:#"top%d_bg.png",index+1]];
NSMutableString *mu = [NSMutableString stringWithString:[NSString stringWithFormat:#"%d",nearest_time]];
if ([time_string length]==3) {
[mu insertString:#"0" atIndex:0];
[mu insertString:#":" atIndex:2];
}
NSString *time=[NSString stringWithFormat:#"%#",mu];
time=[current_timings_array objectAtIndex:index];
time=[time stringByReplacingOccurrencesOfString:#":" withString:#"."];
NSDate *date1;
NSDate *date2;
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"hh.mm"];
date1 = [formatter dateFromString:time];
date2 = [formatter dateFromString:[formatter stringFromDate:[NSDate date]]];
}
// Here I'm calculating the time difference
NSTimeInterval interval = [date1 timeIntervalSinceDate: date2];//[date1 timeIntervalSince1970] - [date2 timeIntervalSince1970];
int hour = interval / 3600;
int minute = (int)interval % 3600 / 60;
// NSLog(#"%# %dh %dm", interval<0?#"-":#"+", ABS(hour), ABS(minute));
label_time_left.text=[NSString stringWithFormat:#"Time left %dh %dm",ABS(hour), ABS(minute)];
I have solved it with my own method, here it is as it may help someone else
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setTimeZone:zone];
[formatter setDateFormat:#"HHmm"];
current_time=[formatter stringFromDate:date];
int current_time_int=[current_time intValue];
nearest_time=2400;
for (int i=0; i<[current_timings_array count]; i++) {
NSString *prayer_timings=[current_timings_array objectAtIndex:i];
prayer_timings=[prayer_timings stringByReplacingOccurrencesOfString:#":" withString:#""];
int calculated_time=[prayer_timings intValue]-current_time_int;
NSLog(#"Nearest Timings %d-%d=%d",[prayer_timings intValue],current_time_int ,calculated_time);
NSString *last_object_time=[current_timings_array.lastObject stringByReplacingOccurrencesOfString:#":" withString:#""];
if (current_time_int>[last_object_time intValue]) {
NSLog(#"It is greated value %d",[last_object_time intValue]);
if (calculated_time<nearest_time ) {
nearest_time=calculated_time;
header_bg_image.image=[UIImage imageNamed:[NSString stringWithFormat:#"top%d_bg.png", i+1]];
}
}
else{
if (calculated_time<nearest_time && calculated_time>0) {
nearest_time=calculated_time;
header_bg_image.image=[UIImage imageNamed:[NSString stringWithFormat:#"top%d_bg.png", i+1]];
}
}
}
I assume you have NSDate objects in your array.
You could make a for cycle:
NSDate *minDate = time.lastObject;
NSTimeInterval minTimeInterval = [minDate timeIntervalSince1970];
NSTimeInterval current = [[NSDate date] timeIntervalSince1970];
for (NSDate *date in time) {
NSTimeInterval interval = [date timeIntervalSince1970];
if (labs(minTimeInterval - current) > labs(interval - current)) {
minDate = date;
minTimeInterval = interval;
}
}
// The minDate is the object you are looking for
I am new to ios development. I am making a custom datepicker using uipickerview. I have datesArray to be used as a data source for uipickerview.
I want to know how to show only Labels : today,tomorrow,Fri,Sat,Sun,Mon,Tues for current week and rest dates in format "EEE, LLL d".
I tried this code but it didn't work.
for(int i=0;i<22;i++)
{
NSDate *myDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * i];
NSDate *now=[NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateFormat:#"EEE, LLL d"];
if(myDate==now)
{
NSString *myDateString=#"today";
[datesArray addObject:myDateString];
}
else
{
NSString *myDateString = [dateFormatter stringFromDate:myDate];
[datesArray addObject:myDateString];
}
}
Try this.Hope it helps
NSString *dateFromWS = #"2013-10-16";//im taking it as static you have to take string coming from webservice
for (int i = 0; i < 22; i++)
{
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter1 setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter1 setDateFormat:#"yyyy-MM-dd"];
NSDate *myDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * i];
NSDate *now = [dateFormatter1 dateFromString:dateFromWS];
NSDate *tomorrow = [NSDate dateWithTimeInterval:60 * 60 * 24 * 1 sinceDate:now];
//NSDate *dummy = [NSDate dateWithTimeInterval:60 * 60 * 24 * 1 sinceDate:now];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateFormat:#"EEE, LLL d"];
NSString *loopDate = [dateFormatter stringFromDate:myDate];
NSString *today = [dateFormatter stringFromDate:now];
NSString *tomorrowString = [dateFormatter stringFromDate:tomorrow];
if ([loopDate isEqualToString:today]) {
[datesArray addObject:#"today"];
} else if ([loopDate isEqualToString:tomorrowString]) {
[datesArray addObject:#"tomorrow"];
} else if ((i/7) < 1) {
[datesArray addObject:[loopDate substringToIndex:3]];
} else {
[datesArray addObject:loopDate];
}
}
if(myDate==now)
is comparing 2 pointers not 2 dates. You need to use the below code
if([myDate compare:now] == NSOrderedSame)
In addition to Simon's pointer issue, your dates will include the time info and so is never likely to be identical. May be the same day but not the same time. You need to find if the day matches. I do this by:
for(int i=0;i<22;i++)
{
NSDate *myDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * i];
NSDate *myDateNoTime = nil;
// Note: Create sysCal as a property so it is not being repeatedly recreated here
[self.sysCal rangeOfUnit:NSDayCalendarUnit startDate:&myDateNoTime interval:nil forDate:myDate];
NSDate *now=[NSDate date];
NSDate *todayDateNoTime = nil;
[self.sysCal rangeOfUnit:NSDayCalendarUnit startDate:&todayDateNoTime interval:nil forDate:now];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateFormat:#"EEE, LLL d"];
if([myDateNoTime isEqualToDate:todayDateNoTime])
{
NSString *myDateString=#"today";
[datesArray addObject:myDateString];
}
else
{
NSString *myDateString = [dateFormatter stringFromDate:myDate];
[datesArray addObject:myDateString];
}
}
Given your server date requirement and, in my opinion, a better way of handling a picker, I would put this in the datasource method instead.
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *resultString = nil;
NSDate *myDate = [self dateForRow:row];
NSDate *myDateNoTime = nil;
// Note: Create sysCal as a property so it is not being repeatedly recreated here
[self.sysCal rangeOfUnit:NSDayCalendarUnit startDate:&myDateNoTime interval:nil forDate:myDate];
NSDate *now=[NSDate date];
NSDate *todayDateNoTime = nil;
[self.sysCal rangeOfUnit:NSDayCalendarUnit startDate:&todayDateNoTime interval:nil forDate:now];
if([myDateNoTime isEqualToDate:todayDateNoTime])
{
resultString = #"Today";
} else {
// Note: using property for date formatter so I am not repeatedly creating here
resultString = [self.dayFormatter stringFromDate:myDate];
}
return resultString;
}
To determine date for the row use:
-(NSDate *)dateFromRow:(NSInteger)inRow {
NSDateComponents *daysToAdd = [[NSDateComponents alloc] init];
[daysToAdd setCalendar:self.sysCal];
NSInteger daysCalc = (-1 * (inRow -2));
[daysToAdd setDay:daysCalc];
NSDate *resultDate = nil;
NSDate *calcDate = [self.sysCal dateByAddingComponents:daysToAdd
toDate:self.myServerDate
options:0];
[self.sysCal rangeOfUnit:NSDayCalendarUnit startDate:&resultDate interval:nil forDate:calcDate];
return resultDate;
}
I suppose you are already set with the way you are doing it but I think you would find this more flexible, no limit to 21 days before or after the server date. Aircode, excuse any typos or syntax errors.
Swift 4.0
for i in 0..<22 {
var myDate = Date(timeIntervalSinceNow: 60 * 60 * 24 * i)
var now = Date()
var dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.dateFormat = "EEE, LLL d"
if myDate == now {
var myDateString = "today"
datesArray.append(myDateString)
} else {
var myDateString: String = dateFormatter.string(from: myDate)
datesArray.append(myDateString)
}
}
Here i am getting current time and check whether its in am/pm format. If its not like that, i convert 24 hour time format into 12 hour time format and add AM/PM manually.
This is my code:
- (NSString *) getCurrentTime {
NSDate *today = [NSDate date];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:#"hh:mm:ss a"];
NSString *currentTime = [timeFormatter stringFromDate:today];
currentTime = [self checkTimeFormat:currentTime];
return currentTime;
}
And
- (NSString *) checkTimeFormat:(NSString *) currentTime
{
NSArray *timeArray = [currentTime componentsSeparatedByString:#":"];
int intHour = [[timeArray objectAtIndex:0] intValue];
NSString *lastVal = [timeArray objectAtIndex:2];
if ([lastVal rangeOfString:#"M"].location == NSNotFound) {
if (intHour < 12)
lastVal = [NSString stringWithFormat:#"%# AM", [timeArray objectAtIndex:2]];
else
lastVal = [NSString stringWithFormat:#"%# PM", [timeArray objectAtIndex:2]];
}
if (intHour > 12)
intHour = intHour - 12;
currentTime = [NSString stringWithFormat:#"%d:%#:%#", intHour, [timeArray objectAtIndex:1], lastVal];
NSLog(#"Current Time ==>> %#", currentTime);
return currentTime;
}
Conversion of NSString into NSDate code below:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"hh:mm:ss a"];
NSDate *testDate = [dateFormatter dateFromString:getCurrentTime];
NSLog(#"testDate => %#", testDate);
If the Time is in 12 hour format (am/pm), testDate value is getting correctly.
If the Time is in 24 hour format, testDate value is null
What is the issue?
Thanks in Advance.
You can try:
NSDate *today = [NSDate date];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:#"HH:mm:ss"];
NSString *currentTime24 = [timeFormatter stringFromDate:today];
[timeFormatter setDateFormat:#"hh:mm:ss a];
NSDate *currentTime12 = [timeFormatter dateWithString:currentTime24];
NSString *currentTime = [timeFormatter stringWithDate:currentTime12];
I am using the below code to try and use current system time to tell me the next time in the array. All it logs out is the last number in the array. I have searched, and this is how I ended up where I am, but could never get it to work just right. Thanks
self.array = #[#"00:15", #"01:35, "#"05:30", #"06:10", #"07:05", #"07:55", #"08:45", #"09:35", #"10:40", #"11:25", #"12:20", #"13:10", #"14:05", #"15:00", #"15:45", #"16:40", #"17:30", #"18:20", #"19:20", #"20:10", #"21:00", #"22:05", #"22:55"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"HH:mm"];
NSDate *formattedCurrentDate = [dateFormat dateFromString:[dateFormat stringFromDate:[NSDate date]]];
for(NSString *stringTime in self.array) {
NSDate *dateFromString = [dateFormat dateFromString:stringTime];
if([formattedCurrentDate earlierDate:dateFromString]) {
self.nextTime.text = stringTime;
}
}
Your code is behaving exactly as it should, you are having it return an earlier time than the current time, which means every single time is assigned to self.nextTime.text, but you only see the very last assignment, which is the last item in the array.
Further more your if statement always returns true if executed correctly, so you will always get true unless you provide an object that is not an NSDate.
Here is the correct way of getting what you would like without having to worry about ordering your array.
NSArray *array = #[#"16:40", #"05:30", #"06:10", #"07:05", #"07:55", #"08:45", #"09:35", #"10:40", #"11:25", #"12:20", #"13:10", #"14:05", #"15:00", #"15:45", #"16:40", #"17:30", #"18:20", #"19:20", #"20:10", #"21:00", #"22:05", #"22:55", #"23:55", #"01:35"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"HH:mm"];
NSDate *formattedCurrentDate = [dateFormat dateFromString:[dateFormat stringFromDate:[NSDate date]]];
NSDate *laterDate;
NSDate *closestDate;
for(NSString *stringTime in array) {
NSDate *dateFromString = [dateFormat dateFromString:stringTime];
laterDate = [formattedCurrentDate laterDate:dateFromString];
if(![laterDate isEqualToDate:formattedCurrentDate]){
closestDate = [laterDate earlierDate:closestDate];
}
}
NSLog(#"Closest Date: %#", [dateFormat stringFromDate:closestDate] );
NSArray *array = #[#"23:15", #"01:35", #"05:30", #"06:10", #"07:05", #"07:55", #"08:45", #"09:35", #"10:40", #"11:25", #"12:20", #"13:10", #"14:05", #"15:00", #"15:45", #"16:40", #"17:30", #"18:20", #"19:20", #"20:10", #"21:00", #"22:05", #"22:55", #"23:55"];
NSMutableArray *datesArray = [[NSMutableArray alloc] init];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"HH:mm"];
//Convert all strings to dates
for (NSString *str in array)
{
NSDate *formattedCurrentDate = [dateFormat dateFromString: str];
[datesArray addObject:formattedCurrentDate];
}
//Sort dates.
NSArray *sortedArray = [datesArray sortedArrayUsingSelector:#selector(compare:)];
NSString *date = [dateFormat stringFromDate:[NSDate date]];
NSDate *formattedTodatDate = [dateFormat dateFromString:date];
//Print the desired date
for(NSDate *stringTime in sortedArray)
{
if([formattedTodatDate compare:stringTime] == NSOrderedAscending)
{
NSLog(#"Result is %#", [dateFormat stringFromDate:stringTime]);
break;
}
}
Try the above code. I just followed what others have mentioned with sorting dates.
If you want a more generic solution, that doesn't depend on the order of the array, you could use the code below:
NSArray *array = #[#"02:25", #"01:35", #"05:30", #"06:10", #"07:05", #"07:55", #"08:45", #"09:35", #"10:40", #"11:25", #"12:20", #"13:10", #"14:05", #"15:00", #"15:45", #"16:40", #"17:30", #"18:20", #"19:20", #"20:10", #"21:00", #"22:05", #"22:55", #"23:55"];
NSDateFormatter *dateFormat = [NSDateFormatter new];
[dateFormat setDateFormat:#"HH:mm"];
NSDate *formattedCurrentDate = [dateFormat dateFromString:[dateFormat stringFromDate:[NSDate date]]];
NSTimeInterval currentInterval = [formattedCurrentDate timeIntervalSince1970];
NSTimeInterval smallerInterval = CGFLOAT_MAX;
for(NSString *stringTime in array) {
NSDate *dateFromString = [dateFormat dateFromString:stringTime];
NSTimeInterval dateFromStringInterval = [dateFromString timeIntervalSince1970];
NSTimeInterval actualInterval = (dateFromStringInterval - currentInterval);
if(actualInterval > 0 && actualInterval < smallerInterval){
smallerInterval = actualInterval;
self.nextTime.text = stringTime;
}
}
This code is getting the closest next hour of the current hour, independent of it's index inside the array. And doesn't require more allocations or any sorting of arrays, like #Sandeep solutions (that do works).
Explaining:
The actualInterval is getting the difference in seconds between all dates and the current date. This variable (which is a double, actually) will only be positive to future hours (past hours will be negative).
So, all the code is doing is getting the smaller difference between future hours. This is, I think, the best solution to this case.
Hope this helped.
if your function works fine.
change:
for(NSString *stringTime in self.array) {
NSDate *dateFromString = [dateFormat dateFromString:stringTime];
if([formattedCurrentDate earlierDate:dateFromString]) {
self.nextTime.text = stringTime;
}
}
to:
for(NSString *stringTime in self.array) {
NSDate *dateFromString = [dateFormat dateFromString:stringTime];
if([formattedCurrentDate compare:dateFromString] == NSOrderedAscending) {
self.nextTime.text = stringTime;
break;
}
}
I have array which is like as below
_combinedBirthdates(
"03/12/2013",
"03/12/2013",
"08/13/1990",
"12/09/1989",
"02/06",
"09/08",
"03/02/1990",
"08/22/1989",
"03/02",
"05/13",
"10/16",
"07/08",
"08/31/1990",
"04/14/1992",
"12/15/1905",
"08/14/1989",
"10/07/1987",
"07/25",
"07/17/1989",
"03/24/1987",
"07/28/1988",
"01/21/1990",
"10/13"
)
all elements are NSString in above NSArray.
How can I make another array which contains number of days remain for particular date
something like this
_newlymadeArray(
"125",
"200",
"50",
"500",
"125",
and so on
)
Use this algorithm:
Obtain the current year
Convert each date from your array to a date in the current year. For example, "03/02/1990" becomes "03/02/2013"
If the date from the step 2 is before the current date, advance its year by one (i.e. "03/02/2013" becomes "03/02/2014")
Using a technique from this question, find the number of days till the date from step 3. It will be less than the number of days in a year.
unsigned int unitFlags = NSDayCalendarUnit;
NSCalendar *currCalendar = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSMutableArray * _newlymadeArray = [[NSMutableArray alloc] init];
for (NSString * str in _combinedBirthdates){
NSDate * toDate = [dateFormatter dateFromString:str];
NSDateComponents *daysInfo = [currCalendar components:unitFlags fromDate:[NSDate date] toDate:toDate options:0];
int days = [daysInfo day];
[_newlymadeArray addObject:[NSString stringWithFormat:#"%d",days]];
}
You need to iterate through the first array and get the date in NSDate and use the info to get the difference in days from the current date to the next date in the array.
You will have to add the necessary checks and this is untested code.
Try this code snap.
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setTimeZone:[NSTimeZone localTimeZone]];
[formatter setDateFormat:#"MM/dd/yyyy"];
NSDate *currentDate = [formatter dateFromString:#"03/12/2013"];
NSTimeInterval srcInterval = [currentDate timeIntervalSince1970];
NSArray *_combinedBirthdates = #[#"03/15/2013", #"05/15/2013"];
NSMutableArray *_newlymadeArray = [NSMutableArray array];
const NSInteger SECONDS_PER_DAY = 60 * 60 * 24;
for (NSString *one in _combinedBirthdates) {
NSDate *destDate = [formatter dateFromString:one];
NSTimeInterval destInterval = [destDate timeIntervalSince1970];
NSInteger diff = (destInterval - srcInterval) / SECONDS_PER_DAY;
[_newlymadeArray addObject:[NSString stringWithFormat:#"%d", diff]];
}
That's it! :)