我需要根据过去10天,过去30天,过去60天等日期从数据库中提取“费用”值。注意:每个费用字段都有一个日期字段,格式为m / dd / yyyy。任何人都可以帮我吗?
答案 0 :(得分:1)
尝试这样,
[NSString stringWithFormat:@"SELECT *FROM tablename WHERE dLastLotteryDate <= '%@'",passDateHere]
编辑: -
像这样检查它会帮助你我想,
> SELECT * FROM tablename WHERE dateField >= date('now','-10 day')
> SELECT * FROM tablename WHERE dateField >= date('now','-30 day')
> SELECT * FROM tablename WHERE dateField >= date('now','-60 day')
答案 1 :(得分:1)
使用此查询:
select * from your_tablename where date_column_name <= your_date
答案 2 :(得分:1)
我假设您已将日期存储在数据库中。
现在要像过去10天那样获取日期,过去30天,过去60天尝试这样,
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *comps = [NSDateComponents new];
comps.days = -10; // Change this as per your need
NSDate *pastDate = [calendar dateByAddingComponents:comps toDate:[NSDate date] options:0]; //This will give you past date
然后将此日期应用于您在此处建议的Sunny。
答案 3 :(得分:0)
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *comps = [NSDateComponents new];
comps.days = -10; // Change this as per your need
NSDate *pastDate = [calendar dateByAddingComponents:comps toDate:[NSDate date] options:0]; //This will give you past date