【问题标题】:Recover a date with SQLite使用 SQLite 恢复日期
【发布时间】:2012-07-19 13:00:21
【问题描述】:

我正在尝试在 iOS 上使用 SQLite 恢复日期。

这个日期(保存在 selectedDate 中)是一个变量 NSDate。我将 NSDate 转换为 NSString(保存在 dateString 中)。

//Code:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat: @"yyyyMMdd"];
NSString *dateString = [formatter stringFromDate:selectedDate];

[formatter release];


NString *sentence = (@"SELECT description, date_from FROM Tasks WHERE date_from = %@", dateString);

//Warning: Expression result unused  :(

如果我输入默认日期,例如:SELECT... WHERE date_from = '20120719',它就会运行。我该如何解决?

对不起我的英语;)谢谢!!!

【问题讨论】:

  • 在我看来你从未执行过 select 语句。

标签: sql ios date sqlite


【解决方案1】:

你试过LIKE=的地方吗?

date_from LIKE '20120719'

NSString *sentence = [NSString stringWithFormat:@"SELECT description, date_from FROM Tasks WHERE date_from = %@", dateString];

【讨论】:

  • 非常感谢!!! NSString *sentence = [NSString stringWithFormat:@"SELECT description, date_from FROM Tasks WHERE date_from = %@", dateString]; //没问题
猜你喜欢
  • 1970-01-01
  • 2015-05-16
  • 1970-01-01
  • 2014-08-12
  • 2013-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多