我想显示上周的记录&删除我的iPhone应用程序中以前的记录。
所以我使用获得一周后的日期时间
//Now
nowDate = [entryDateFormat stringFromDate:[NSDate date]];
//1 week previous
weekDate = [entryDateFormat stringFromDate:[[NSDate date] dateByAddingTimeInterval: -604800.0]];
然后,执行类似的SQL查询
NSString *selectSQL = [NSString stringWithFormat:@"SELECT * FROM tblTest Where Time between "%@" and "%@"", weekDate, nowDate];
因此,获取Query的值::
SELECT * FROM tblTest Where Time between "04-02-2013 17:20:36" and "11-02-2013 17:20:36";
与删除以前的记录相同
Delete FROM tblTest Where Time < "04-02-2013 17:20:36";
所以,它只适用于第一、第二和第三;当前日期的第3天。
它不会在上个月的日期执行,如"2013年1月30日"&2013年1月31日。
我也尝试过:
Delete FROM tblTest Where Time < DATE('now','-7 days');
但没有结果(
sqlite端的函数是什么,所以我们可以根据这些函数执行操作,并获得上周记录的确切值。?
这种情况请帮帮我。
提前谢谢。
在SQLite中,时间戳应该首先与年份字段一起存储,即格式为CCD_。
首先,
为了节省时间,
NSTimeInterval currentTimeStamp = [[NSDate date] timeIntervalSince1970];
NSNumber *currentTimeStampObj = [NSNumber numberWithDouble: currentTimeStamp];
[currentTimeStampObj retain];
并将其作为新的"进入时间"字段存储到数据库中。
当显示数据&删除以前的数据
//Date Formatter
NSDateFormatter *entryDateFormat;
//Now Date & Previous Date
NSString *nowDate, *weekDate;
NSNumber *currentNowTimeStamp, *pastWeekDateTimeStamp;
//Today
nowDate = [entryDateFormat stringFromDate:[NSDate date]];
NSTimeInterval currentTimeStamp = [[NSDate date] timeIntervalSince1970];
currentNowTimeStamp = [NSNumber numberWithDouble:currentTimeStamp];
[currentNowTimeStamp retain];
NSLog(@" Time :::: %@", currentNowTimeStamp);
//Past Week Date
weekDate = [entryDateFormat stringFromDate:[[NSDate date] dateByAddingTimeInterval: -604800.0]];
currentTimeStamp = [[[NSDate date] dateByAddingTimeInterval: -604800.0] timeIntervalSince1970];
pastWeekDateTimeStamp = [NSNumber numberWithDouble: currentTimeStamp];
[pastWeekDateTimeStamp retain];
NSLog(@" Past Week Time :::: %@", pastWeekDateTimeStamp);
查询::
NSString *deleteSQL = [NSString stringWithFormat:@"Delete FROM tblTest Where entry time < "%@"", pastWeekDateTimeStamp];
结果::Delete FROM tblTest Where entry time < "1360392911.010868"
NSString *selectSQL = [NSString stringWithFormat:@"SELECT * FROM tblTest Where Time between "%@" and "%@"", pastWeekDateTimeStamp, currentNowTimeStamp];
结果::SELECT * FROM tblTest Where entry time between "1360392911.010868" and "1360997711.010534"
我得到了我想要的精确解决方案。
干杯。。!!
快乐编码。。