Possible Duplicate:
How to compare two NSDate objects in objective C
1---> I'm new to Objective-C and stuck at a point. The concept is of type booking slots/reservation, which means cannot book a slot at previous time and previous date. I have to compare today's date with a particular date may be less than today's date or greater than today's date.
For getting current date I have done this :
NSDate *date = [NSDate date];
NSDateFormatter *formatter = nil;
formatter=[[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
I have a date which is to be compared with todays date in UItextField which is also in yyyy-MM-dd format.
Now I have to compare today's date with the textField date.But I'm not getting it ..
if(textfielddate<currentdate)
{
NSLog(@"You cannot book a slot at past date);
}
but here it is not getting compared..
2---> I need to compare a time in 24hr format with currenttime which is also in 24hr format..
I have a particular time in a string variable 12:00,11:00,15:00 etc .Now I need to compare this with the current time in 24 hr format .
if([time <= currenttime] && [textFielddate==currentdate])
{
NSLog(@"You cannot book a slot at past time ");
}
How can I do it?