Reputation: 4770
Hi I am having two date as string , that is assigned to two labels,
one label holds current date string, that is may 29, 2010
similarly the other date will be selected by user in this same format, i need to check the user date is present, past , or future. by comparing with current date string.
please provide some sample code.
Thanks in advance.
Upvotes: 2
Views: 7358
Reputation: 502
Here's the code I used to solve this problem:
[Lout setStringValue:mydates];
NSDate* dateDB = [NSDate date];
NSDate* date = [NSDate date];
//Create the dateformatter object
NSDateFormatter* formatterDate = [[[NSDateFormatter alloc] init] autorelease];
[formatterDate setDateFormat:@"MM-dd-yy HH:mm:ss"];
dateDB = [formatterDate dateFromString:value3];
NSLog([NSString stringWithFormat:@"date value = %@",[formatterDate stringFromDate:dateDB]]);
NSTimeInterval timeInt = [[NSDate date] timeIntervalSinceDate:dateDB];
timeInt = timeInt/60;
This code will give you elapsed time in minutes. (It will give a negative number if the "since" date is in the future.)
Upvotes: 1
Reputation: 502
simple... Comparing Dates
These are all in NSDate documentation which u can access by pressing the help button on menu and then selecting Developer Documentation...type in search NSDate.then what u need is compare.....
IF AND ONLY IF u want it to be present...put a check as special case if the dd/MM/YYYY are same, say its a present value...OR USE isEqualToDate...... IF the comparison with current date gives a negative value....its future.. IF the comparison with current date gives a positive value....its past...
Upvotes: 3