I am new to iOS programming, and I have searched a lot for a way to compare today (NSDate) with formatted string date (dd / MM / yyyy).
I found some good answers with NSDate earlierDate, laterDateetc., but the code does not seem to work in my project.
there he is:
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
if ( [[dateFormat dateFromString:[book quandd]] isEqualToDate:today]) {
NSLog(@"Dates are equal");
}
if ( [[dateFormat dateFromString:[book quandd]] earlierDate:today]) {
NSLog(@"earlier");
}
if ( [[dateFormat dateFromString:[book quandd]] laterDate:today]) {
NSLog(@"later");
}
No matter what I do and whatever the date in [book quandd], the console always writes βearlierβ and βlaterβ, as if they were later and earlier at the same time as today.
Where does this error appear?
Is there a simple / simpler way to compare today's date with 02/26/2011, for example?
source
share