views:

60

answers:

1

Hey gays , I have the date function.And I have to compare the previous date with current data in iphone

For current date I have code:-

NSDate* date = [NSDate date];

//Create the dateformatter object
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];

//Set the required date format
[formatter setDateFormat:@"yyyy-MM-dd"];

//Get the string date
NSString* str = [formatter stringFromDate:date];

//Display on the console
NSLog(str);

//Set in the lable
[dateLabel setText:str];

But I want to implement the compare the current date & previous date in iphone

Thanks in advance

+2  A: 

You can compare dates using NSDate's comparison methods:

- (NSDate *)earlierDate:(NSDate *)anotherDate;
- (NSDate *)laterDate:(NSDate *)anotherDate;
- (NSComparisonResult)compare:(NSDate *)other;

- (BOOL)isEqualToDate:(NSDate *)otherDate;

Check NSDate class reference to know more..

lukya
thank you Can you explain me more on this or give me sample code for this
did you read the class reference? - http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html If you open the instance methods section on the left, you can read details about each of these methods. If you have been able to use NSDateFormatter, i don't think you'll need more explanation on this.
lukya
if its a different problem ask a different question. and i don't think any one on stack overflow is going to 'give you a solution' for something just like that, ask a question describing what are you trying to do, what have you done so far and where you are stuck... then people will respond..
lukya