【发布时间】:2013-07-19 05:43:51
【问题描述】:
我需要根据过去 10 天、过去 30 天、过去 60 天等日期从数据库中提取我的“费用”值。注意:每个费用字段都有一个格式为 m/dd/yyyy 的日期字段。谁能帮我解决这个问题?
【问题讨论】:
我需要根据过去 10 天、过去 30 天、过去 60 天等日期从数据库中提取我的“费用”值。注意:每个费用字段都有一个格式为 m/dd/yyyy 的日期字段。谁能帮我解决这个问题?
【问题讨论】:
我假设您已将日期存储在数据库中。
现在要获取过去 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 在此处的建议将此日期应用于您的查询。
【讨论】:
使用这个查询:
select * from your_tablename where date_column_name <= your_date
【讨论】:
试试这样,
[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')
【讨论】:
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
【讨论】: