tags:

views:

63

answers:

5
    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

+4  A: 

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.
Vladimir
+2  A: 

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 ) {
    ...
}
martin clayton
+4  A: 

The easiest method i'm aware is:

if( [firstDate timeIntervalSinceDate:secondDate] > 0 ) {

The other answers cover compare:, wanted to add some flavour ;).

dannywartnaby
clever idea :) +1
lukya
A: 

Take a look at this: http://www.iphonedevsdk.com/forum/iphone-sdk-development/12093-nsdate-isbetween.html

I think thats what you need

Lily
+1  A: 

What about...

if ([datStartDate earlierDate: datEndDate] == datStartDate) {
    // datStartDate is earlier
} else {
    // datEndDate is earlier
}
Kevin Mitts