I want to check whether the date limit*(Ex:- 22/07/2013 2:30PM -22/07/2013 8:30PM )* comes with in another time limit*(Ex:- 22/07/2013 4:30PM -22/07/2013 6:30PM )* or not. I am completely new to this concept. Can anyone please tell me how to do this.
Any help will be highly appreciated
Below is the code I tried:
- (void)viewDidLoad
{
[self isDateInterval:@"8/1/2013 8:30am" and:@"8/1/2013 8:40am" fallsWithin:@"8/1/2013 8:30am" and:@"8/1/2013 8:55am"];
[super viewDidLoad];
}
-(BOOL)isDateInterval:(NSString*)startDate1 and:(NSString*)endDate1 fallsWithin:(NSString*)startDate2 and:(NSString*)endDate2
{
BOOL isWithinrange;
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd/MM/yyyy hh:mmaa"];
NSTimeInterval ti1 = [[formatter dateFromString:startDate1] timeIntervalSince1970];
NSTimeInterval ti2 = [[formatter dateFromString:endDate1] timeIntervalSince1970];
NSTimeInterval ti3 = [[formatter dateFromString:startDate2] timeIntervalSince1970];
NSTimeInterval ti4 = [[formatter dateFromString:endDate2] timeIntervalSince1970];
if( (ti3 > ti1 && ti3 < ti2) || (ti3 < ti1 && ti4 > ti1) )
{
//Date with in range
isWithinrange=TRUE;
}
else
{
isWithinrange=FALSE;
//Not with in range
}
return isWithinrange;
}
I want the output to be "isWithin" as because part of the time interval of one is coming into the other time interval