I want to check if user selected date is the same as the current date or not. I am using this code. I can check if the selected date is in the past or future, but I can't detect if it is the same, because when I log both dates it is in this format. I mean there is difference between today date time and the selected date time. So it is considered as less. Here is log:
selected date:2014-01-03 05:53:53 +0000 , today date: 2014-01-03 05:54:20 +0000
Here is my code:
NSDate *today = [NSDate date]; // it will give you current date
NSDate *newDate = datePicker.date; // your date
NSComparisonResult result;
// has three possible values: NSOrderedSame,NSOrderedDescending, NSOrderedAscending
NSLog(@"selected date:%@ , today date: %@",newDate,today);
result = [today compare:newDate];
NSLog(@"result %d",result);
if(result==NSOrderedAscending)
{
NSLog(@"big ascending");
[AJNotificationView showNoticeInView:[[UIApplication sharedApplication] delegate].window
type:AJNotificationTypeRed
title:@"Birthdate should be less than today date."
linedBackground:AJLinedBackgroundTypeDisabled
hideAfter:GZAJNotificationDelay];
return;
}
else if(result==NSOrderedDescending){
NSLog(@"fine");
[UIView animateWithDuration:0.25 delay:0.0 options: UIViewAnimationOptionCurveEaseInOut
animations:^{
// self.view.frame=CGRectMake(0, -30, 320, 200);
subview.frame=CGRectMake(0, 640, 320, 180);
// CGRect f1;
// f1=self.view.frame;
// f1.origin.y=f1.origin.y-100;
// self.view.frame=f1;
// v1.backgroundColor=[UIColor blackColor];
}
completion:^(BOOL finished){
if(finished) {NSLog(@"Finished end !!!!!");}
}];
}
else{
NSLog(@"same");
[AJNotificationView showNoticeInView:[[UIApplication sharedApplication] delegate].window
type:AJNotificationTypeRed
title:@"Birthdate should be less than today date."
linedBackground:AJLinedBackgroundTypeDisabled
hideAfter:GZAJNotificationDelay];
return;
}