Fry
Fry

Reputation: 922

objective-c method to check if date is between to others

i have two NSDates and i want to check if a third one is between those others. But now, even if i know that the date i want to check is between the others, it says its not. Maybe one of you can help me.So the if-clause is always TRUE.

Thanks a lot!!

current = [ar objectAtIndex:j];
            gameDate = [current gameDate];
            gameDate = [gameDate substringToIndex:[gameDate length] - 9]; 
            GameDay = [df dateFromString:gameDate];

            if(![GameDay compare:start] == NSOrderedAscending && ![GameDay compare:end] == NSOrderedDescending){
                [DateArray addObject:[ar objectAtIndex:j]];
            }

Upvotes: 2

Views: 230

Answers (1)

Oscar Gomez
Oscar Gomez

Reputation: 18488

You can try simply using the NSDate NSTimeInterval (which is really just a typeDef for double) and comparing like this:

if ([myCheckDate timeIntervalSince1970] < [mybetweenDate1 timeIntervalSince1970] && [myCheckDate timeIntervalSince1970] > [mybetweenDate2 timeIntervalSince1970])

Hope that helps.

Upvotes: 2

Related Questions