Christopher Francisco
Christopher Francisco

Reputation: 16268

CoreData NSPredicate date() function

I'm trying to use the following predicate:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ending_date < date('now')", nil];

But I'm getting NSInvalidArgumentException', reason: 'Unable to parse function name 'date:' into supported selector (date:) ' so I guess maybe the date('now') is not supported on iOS version of SQLite

how can I accomplish it?

Upvotes: 0

Views: 744

Answers (2)

Nicol&#242; Ciraci
Nicol&#242; Ciraci

Reputation: 678

You should use the NSExpression now instead of date:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ending_date < now", nil];

Upvotes: 0

andrewbuilder
andrewbuilder

Reputation: 3791

You could try this...

NSDate *dateNow = [NSDate date];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ending_date < %@", dateNow];

Upvotes: 1

Related Questions