I want to compare the todays date and other date coming from my database. For example, 2011-03-25 compare it with 2011-02-25
How can i formate my database date as the NSDateFormatter require NSDdate datatype ?
I want to compare the todays date and other date coming from my database. For example, 2011-03-25 compare it with 2011-02-25
How can i formate my database date as the NSDateFormatter require NSDdate datatype ?
In Swift:
Cocoa has couple of methods for this:
in NSDate
– isEqualToDate:
– earlierDate:
– laterDate:
– compare:
When you use - (NSComparisonResult)compare:(NSDate *)anotherDate ,you get back one of these:
for more read the SO post
Just go through the blog post, there are many date related utility functions.
http://arstechnica.com/apple/guides/2010/03/how-to-real-world-dates-with-the-iphone-sdk.ars/2
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DatesAndTimes/Articles/dtDates.html#//apple_ref/doc/uid/20000183-BCIDBADB
Isn't that the same on Iphone?
If your date are string like year-month-day, you can just compare string:
It will works because fields in date are from most important to less, like a string comparison.
You can use NSDate compare: or timeIntervalSinceReferenceDate -- that'll get you started