Reputation: 4079
i Have 2 NSDate
object the first is set to one month ahead and the seconed is set for today.
i want to check if today is after (Bigger) then the month ahead object.
How can i do it?
Upvotes: 1
Views: 10567
Reputation: 16827
NSDate* earlierDate = [aDate earlierDate:anotherDate];
Return Value The earlier of the receiver and anotherDate, determined using timeIntervalSinceDate:. If the receiver and anotherDate represent the same date, returns the receiver.
Upvotes: 2
Reputation: 32681
Read the Date and Time Programming Guide a lot of Date & Time concepts (and how Cocoa handle them) are explained here in details, it is really worth reading.
Also, in the NSDate class Reference, you can find a dedicated section "Comparing dates" for all the methods used to compare two dates. So you should use laterDate:
or earlierDate:
methods that totally answer your question. You can also use the timeIntervalSinceDate:
method and check the sign of the returned time interval (see once again the documentation on this)
In general, don't hesitate to read the documentation as everything is already explained in there in detail as you can see given those links
Upvotes: 4
Reputation: 21582
You can use NSDate's compare
method. Example:
switch ([dateOne compare:dateTwo]) {
case NSOrderedAscending:
// dateOne is earlier in time than dateTwo
break;
case NSOrderedSame:
// The dates are the same
break;
case NSOrderedDescending:
// dateOne is later in time than dateTwo
break;
}
Upvotes: 11
Reputation: 2144
go to this link:
other wise convert your date to double and compare it. all related function are in this link.
Upvotes: 0