Question

hi i want to know how to get current date? i want to compare current date with a date i m fetching from a plist files using following code.

NSDate *expDate = [licenseDictionary objectForKey:@"Expires"];

for comparison i m using the following code

if([curDate compare:expDate] == NSOrderedAscending )

but its not working. can anybody help me.

Was it helpful?

Solution

In the interest of teaching someone how to fish rather than just feeding him:

Have a look at the Date and Time Programming Guide.. The Programming Guides in the documentation are your first stop when trying to understand a topic. They provide an overview of what can be done and contain useful example code.

These guides also have links to the documentation of the specific classes that are used. In this case there is the NSDate Class Reference which has sections on creating dates and comparing dates.

Edit

To answer you comment about this not working, I think the problem could be that you haven't created the object that you've stored in the dictionary as an NSDate. Again. Have a look at the creating dates documentation. It will be something like

NSDate *expiryDate = [NSDate dateWithNaturalLanguageString:@"31/01/10"];

But this is just an example, there are other ways of setting a date string.

OTHER TIPS

To get the current date, simply use:

NSDate * today = [NSDate date];

To compare to another date:

if ([today compare:expirationDate] == NSOrderedAscending)
{
    // today's date is before the expiration date
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top