Reputation:
I need to get objects from parse that not older then a week. i was trying it with
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE, MMMM d yyyy"];
NSDate *date = [object createdAt];
[dateFormatter stringFromDate:date]
Upvotes: 0
Views: 307
Reputation: 17170
Your code is a long way from working and shows some basic misunderstandings. I think you really need to go and learn about Objective-C and Cocoa/UIKit before you jump into Parse. However:
Parse has an automatic column called createdAt
on all objects. You should use that.
I'm not sure about your definition of "a week ago" but to get a date exactly one week ago to the second use:
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:-60*60*24*7];
There are more complex ways of doing this if you mean "midnight one week ago" or something like that but I'll leave this as is for the sake of clarity.
Pass this date to a PFQuery using the built in createdAt column:
PFQuery* q = [PFQuery queryWithClassName:[MyClass parseClassName]];
[q whereKey:@"createdAt" greaterThan:date];
Then issue the find:
[q findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
// here objects will contain your PFObject subclasses from the server
}];
Upvotes: 2