if (datStartDate > datEndDate) {
This doesn't seem to work. I know theres a isEqual etc, but how do i perform is greater than ?
There are both NSDate
if (datStartDate > datEndDate) {
This doesn't seem to work. I know theres a isEqual etc, but how do i perform is greater than ?
There are both NSDate
To compare dates use -compare:
method:
Return Value If:
- The receiver and anotherDate are exactly equal to each other, NSOrderedSame
- The receiver is later in time than anotherDate, NSOrderedDescending
- The receiver is earlier in time than anotherDate, NSOrderedAscending.
As you have NSDates:
NSDate *datStartDate = [NSDate dateWithString:@"2010-10-01 03:00:00 +0900"];
NSDate *datEndDate = [NSDate dateWithString:@"2010-10-01 04:00:00 +0900"];
if ( ([datStartDate compare:datEndDate]) == NSOrderedDescending ) {
...
}
The easiest method i'm aware is:
if( [firstDate timeIntervalSinceDate:secondDate] > 0 ) {
The other answers cover compare:, wanted to add some flavour ;).
Take a look at this: http://www.iphonedevsdk.com/forum/iphone-sdk-development/12093-nsdate-isbetween.html
I think thats what you need
What about...
if ([datStartDate earlierDate: datEndDate] == datStartDate) {
// datStartDate is earlier
} else {
// datEndDate is earlier
}