Q:

NSDate conversion issue when input NSDate format is unknown and separate Date and Time

I get null date even when the string that I pass has a date as shown below:-
Generic input Date Format is "MM/dd/YYYY hh:mm a"
NSString input Date can be one of the following: "12/1/2012"  , "12/1/2012 01:43 am" , "01:43 am"
Expected output which I am trying is that , it must print date if it exists in input string and time must be printed out if it exists in the input string.
Input:-
 [self testDate:@"12/1/2012"]

Code:-
-(void) testDate:(NSString*) str{
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM/dd/yyyy hh:mm a"];//My Generic Date Format
    self.dateTest=[formatter dateFromString:str];
    [self printDate:self.dateTest];
}

-(void) printSeparatedDateAndTime:(NSDate*) date{
    NSDateFormatter *dateF=[[NSDateFormatter alloc] init];
    [dateF setDateFormat:@"MM/dd/yyyy"];
    NSString *dateStr=[dateF stringFromDate:date];
    NSLog(@"Date= %@",dateStr);

    [dateF setDateFormat:@"hh:mm a"];
    NSString *timeStr=[dateF stringFromDate:date];
    NSLog(@"Time= %@",timeStr);
}

Output Date:- 
Date= (null)
Time= (null)
Input can be in any format, ex 
input
"12/1/2012"
output
date="12/1/2012"
time=null
input
"12/1/2012 01:43 am"
output
date="12/1/2012"
time=01:43 am
input
"01:43 am"
output
date=null
time="01:43 am"
One can get a different answer here Objective-C String(yyyy-mm-dd) to NSDate. This refers to answer if date format set is wrong.
In my case date format is correct. But it might have only date, only time or both of them.
To separate date and time from a String one can refer here ios4 - splitting a date and time from a string into two separate strings, but it does not have a checked answer or a valid answer.

A:

Remove hh:mm a  and the format can be either "MM/dd/yyyy" or "dd/MM/yyyy".
-(void) testDate:(NSString*) str{
    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd/MM/yyyy"];
    self.dateTest=[formatter dateFromString:str];
    [self printDate:date];
}

Your printeDate: will not work as expected since the date created don't have any information about the time and you are trying to show hours and minutes.It will always show 12.00 AM.
If you want to show hours and minutes you need to include that also in your input string.
EDIT : Since dateFormats can be in three formats you need to do a trial and error.
-(void) testDate:(NSString*) str{

    NSArray *dateFormats = @[@"dd/MM/yyyy",@"hh:mm a",@"dd/MM/yyyy hh:mm a"];

    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
    NSDate *date = nil;

    for (NSString *dateFormat in dateFormats) {
        [formatter setDateFormat:dateFormat];
        date = [formatter dateFromString:str];
        if (date) {
            break;
        }
    }

    [self printDate:date];
}

OR 
-(void) testDate:(NSString*) dateString
{
    NSDate *date = nil;
    NSError *error = nil;
    NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeDate
                                                               error:&error];
    NSArray *matches = [detector matchesInString:dateString
                                         options:0
                                           range:NSMakeRange(0, [dateString length])];
    for (NSTextCheckingResult *match in matches) {
        if (match.date) {
            date = match.date;
            break;
        }
    }

    [self printDate:date];
}

EDIT 2 : As it is a requirement to have data/time to nil out. Please try 
typedef enum {
    ValidDateType = 0,
    ValidTimeType = 1,
    ValidDateTimeType =2
}ValidType;

- (void)testDate:(NSString*) dateString
{
    NSArray *dateFormats = @[@"dd/MM/yyyy",@"hh:mm a",@"dd/MM/yyyy hh:mm a"];

    NSDateFormatter *formatter=[[NSDateFormatter alloc] init];

    __block NSDate *date = nil;
    __block ValidType type = ValidDateType;

    [dateFormats enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSString *dateFormat = (NSString *)obj;
        [formatter setDateFormat:dateFormat];
        date = [formatter dateFromString:dateString];
        if (date) {
            type = idx;
            *stop = TRUE;
        }

    }];

    [self printDate:date validType:type];
}

- (void)printDate:(NSDate*) date validType:(ValidType)type
{
    NSDateFormatter *dateF=[[NSDateFormatter alloc] init];
    [dateF setDateFormat:@"MM/dd/yyyy"];
    NSString *dateStr=[dateF stringFromDate:date];

    [dateF setDateFormat:@"hh:mm a"];
    NSString *timeStr=[dateF stringFromDate:date];

    dateStr = (type == ValidTimeType)?nil:dateStr;
    timeStr = (type == ValidDateType)?nil:timeStr;

    NSLog(@"Time= %@",timeStr);
    NSLog(@"Date= %@",dateStr);

}

