Quote:
Originally Posted by StefanL
Hi Folks,
I need to compare some dates and put them in an "if - else" statement:
I have the "NOW Date", the "Give Date" and then I have "Given Date MINUS 10 Minutes". Now I should compare whether NOW Date is "smaller" then "Given Date minus 10 Minutes", and if YES then an action should be started:
Code:
NSDate *myDate = [NSDate date];
NSDate *aktDate = [Date from DB];
NSDate *tenMinutes = [aktDate dateByAddingTimeInterval:-60*10];
This is my result so far - I have no clue how I can get NOW > [Given Date MINUS 10 Minutes]
Thanks a lot for your help and advice!
BR,
Stefan
|
You can certainly work with NSDate objects, and create a new date for "given minus 10 minutes".
I prefer working with the NSDate methods that return a floating point number that represents the date:
[NSDate timeIntervalSinceReferenceDate]
returns a floating point value that's the number of seconds passed since January 1, 2001.
You can save your start date as a time interval, then get the date at the the end time, and do simple floating point math on the two dates to calculate the number of seconds between them.
I like those methods because you can use them without having to create date objects and worry about retaining/releasing them..
There are also methods like
Code:
- (NSTimeInterval)timeIntervalSinceReferenceDate
That give you the NSTimeInterval value for an existing date, timeIntervalSinceNow, etc.