Re: Comparing dates
Re: Comparing dates
- Subject: Re: Comparing dates
- From: Jeff LaMarche <email@hidden>
- Date: Fri, 26 Sep 2003 09:20:03 -0400
On Thursday, September 25, 2003, at 08:57 PM, April Gendill wrote:
How do I compare two different dates?
lets say, I have scheduled an even for September 30 2003, and I want
to know if it is that date yet.. How do I do that I can't seem to get
my head wrapped around the NSDate and NSCalanderDate clases
I hate to ask if you've RTFM, but it's actually very straight
forward....
The generic method for comparing dates is:
- (NSComparisonResult)compare:(NSDate *)anotherDate
so say, we have two dates:
NSDate *firstDate, *secondDate;
which get set to values somewhere along the line. We want to find out
which is first, you could do something like (this is not real code
that's been compiled, so no warranties, etc):
NSComparisonResult rslt = [firstDate compare:secondDate];
switch (rslt)
{
case NSOrderedSame:
// They are the same date
break;
case NSOrderedDescending:
// firstDate is earlier than secondDate
break;
case NSOrderedAscending:
// firstDate is after secondDate
break;
}
or you can use the convenience methods:
- earlierDate:
Compares the receiver to the argument and returns the earlier of the
two.
- isEqualToDate:
Returns YES if the receiver and the argument are equal.
- laterDate:
Compares the receiver to the argument and returns the later of the two.
It's all right there in the NSDate documentation...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.