【问题标题】:SQLite select rows if timestamp matches today's date如果时间戳与今天的日期匹配,SQLite 选择行
【发布时间】:2014-07-05 23:05:59
【问题描述】:

如果条目时间戳与今天的日期匹配,我想从 SQLite 表中选择所有条目。

我正在查询一个 SQLite 数据库,如下所示:

// Tasks table name
private static final String TABLE_TASKS = "tasks";

// Tasks Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_TIMESTAMP = "timestampGMT";
private static final String KEY_DESCRIPTION = "description";


String selectQuery = "SELECT  * FROM " + TABLE_TASKS + " WHERE "+ KEY_TIMESTAMP+">=date('now', '-1 day')";

这是我最接近的行为,但我不希望选择过去 24 小时内的所有条目。我只想选择今天的日期是否与时间戳匹配。

如何只选择表中时间戳与今天日期匹配的行。

数据库中的日期格式为:2014-07-05 12:59:35。

【问题讨论】:

    标签: android sqlite android-sqlite


    【解决方案1】:

    这行得通吗?

    date('now', 'start of day')
    

    【讨论】:

    • 我如何考虑时区?例如复活节时间是 GMT -4。所以我需要 date('now', 'start of day -4') 之类的东西,但这显然行不通
    • 想通了 答案:date('now', 'start of day', 'localtime')
    【解决方案2】:

    对于当地时区:

    date('now','localtime','start of day')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-27
      • 1970-01-01
      • 2014-09-24
      • 2012-04-14
      • 2013-11-25
      相关资源
      最近更新 更多