I wanted to compare a user input date string to current date. My requirement is that,the date entered by the user should always be a future date.
For this, I am converting the string value to date and comparing to [NSDate date]
. But dateFromString
is always returning a date prior to user entered date.
Here is my code:
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yy"];
NSDate *myDate=[dateFormatter dateFromString:@"04/11/2014"];
NSComparisonResult result = [(NSDate*)[NSDate date] compare:myDate];
NSLog(@"myDate is %@",myDate);
NSLog(@"currrent date is %@",[NSDate date]);
if(result==NSOrderedDescending)
{
NSLog(@"the date entered is past date");
}
And following is the output:
myDate is 2014-04-10 18:30:00 +0000
currrent date is 2014-04-11 09:23:28 +0000
the date entered is past date
How do I compare the string date to current date. (My timezone is IST- GMT + 5:30).