简体   繁体   English

使用 FMDB 基于日期的查询过滤?

[英]Query filtering based on dates using FMDB?

How do I query games that are after a "visible" date?如何查询“可见”日期之后的游戏? The dateformat is set:日期格式设置为:

FMDatabase *db = self.database;
if([self.database open]){
    [db beginTransaction];

    NSDateFormatter *formatter = [NSDateFormatter new];
    [formatter setDateFormat:@"yyyy-dd-MM'T'HH:mm:ss'Z'"];
    [db setDateFormat:formatter];
    ...
}

The table is created the following way:该表的创建方式如下:

[db executeUpdate:@"CREATE TABLE IF NOT EXISTS game (gameId Varchar(36) NOT NULL PRIMARY KEY,name TEXT,visibleFrom TEXT)"];

The query is executed the following way:查询按以下方式执行:

FMResultSet *results = [db executeQuery:@"SELECT * FROM game WHERE game.visibleFrom >= ?,[NSDate date]];

This returns nothing.这不返回任何内容。 When I use select * from game then i get all the games.当我使用select * from game然后我得到所有的游戏。 But I need the filtered result.但我需要过滤后的结果。 Thanks in advance.提前致谢。

查看查询日期的 SQLite 语法: sqlite select with condition on date您可能需要类似 '@" ... where date > date(?)", formattedDate', where formattedDate is formatted like '1980-12- 31'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM