Hank Brekke
Hank Brekke

Reputation: 2024

iPhone SDK - Number of days between day and today

I need help on how to find out how many days it has been (seven day weeks, MSTimezone) since May 6th, 2009

[NSDate *m62009 = [NSDate dateWithTimeIntervalSinceReferenceDate:231638400]; [m62009 setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"MST"]; (to help you - 231638400 seconds from 1/1/2001)


Edit:
And then how can I convert the NSTimeInterval into days as an integer or string

Upvotes: 1

Views: 1177

Answers (2)

Josh Polk
Josh Polk

Reputation: 265

I suggest relaying this through another integer saying "Set integer created for this use here to (That comparing day's number out of 365 - Today's day number out of 365)"

Upvotes: 0

KushalP
KushalP

Reputation: 11206

This has been covered here, but the solution you're looking for should be something like the following:

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];

NSDate *date1 = [dateFormatter dateFromString:@"2009-05-06"];
NSDate *date2 = [NSDate date]; // Should produce today's date

NSTimeInterval diff = [date2 timeIntervalSinceDate:date1]

You can then format the NSTimeInterval as you see fit.

Upvotes: 1

Related Questions