I have a problem comparing datetime. I can retrieve it normally but can't compare it. I have a datetime and string implementation is like this:
yyyy-MM-dd'T'HH:mm:ss
That is ok. I use formatter:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
NSDate *dateTo = [formatter dateFromString:[banners[i] DateValidTo]];
That gives me this: 2016-06-19 22:00:00 +0000
I save this record and it writes in Sqlite in float? I need to compare dates, for expired dates. I use this:
NSPredicate *expiredDateFilter = [NSPredicate predicateWithFormat:@"dateTo < %@", [NSDate date];
NSArray *banners = [Banner MR_findAllWithPredicate:expiredDateFilter];
This returns nothing. I have one record that its expired date is in april of this year. I've tried saving this as double (NSNumber) and using timeIntervalSince1970 and save it that way. It is of course a double so that is again a problem. My question is, how to properly save a Datetime to a database and secure that it can be compared?
Aucun commentaire:
Enregistrer un commentaire