当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - How to get data with respect to Month and Year

问题描述:

I have core data with Entity @"Collection" with attributes payment, date etc and i stored "date"

with respect to date,month,year like "dd-MM-yyyy" but i want to fetch data with respect to only Month and Year so for this purpose what NSPredicate i use. If any one known this then kinldy guide me.

网友答案:

As Droppy commented use NSDate as the field type.

If that is not possible you can fetch the rows you are interested in by using a NSPredicate:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K LIKE[cd] %@", kDateFieldKey, [NSString stringWithFormat:@"*-%02d-%d", month, year]];
fetchRequest.predicate = predicate;

where kDateFieldKey is the key for your date field ("date"), month is an integer representing the month and year is an integer representing the year.

分享给朋友:
您可能感兴趣的文章:
随机阅读: