How to Check if an NSDate occurs between two other NSDates

I came up with a solution. If you have a better solution, feel free to leave it and I will mark it as correct.

+ (BOOL)date:(NSDate*)date isBetweenDate:(NSDate*)beginDate andDate:(NSDate*)endDate
{
    if ([date compare:beginDate] == NSOrderedAscending)
        return NO;

    if ([date compare:endDate] == NSOrderedDescending) 
        return NO;

    return YES;
}

Leave a Comment