gpt4 book ai didi

android - 如何在 SQLite 中查询等于今天的日期?

转载 作者:行者123 更新时间:2023-12-05 00:17:06 25 4
gpt4 key购买 nike

如何进行查询以仅从数据库中检索时间等于“今天”的记录。我将日期存储为文本(yyyy-MM-dd HH:mm:ss)?

这是我的表格的样子:

// TABLE EVENT
private static final String TABLE_EVENT = "event";
private static final String TABLE_EVENT_ID = "_id";
private static final String TALBE_EVENT_START_TIME = "start_time";
private static final String TALBE_EVENT_END_TIME = "end_time";
private static final String TALBE_EVENT_NOTE= "note";

private static final String CREATE_TABLE_EVENT = "CREATE TABLE "
+ TABLE_EVENT + " ("
+ TABLE_EVENT_ID + " integer primary key autoincrement, "
+ TALBE_EVENT_START_TIME + " text not null, "
+ TALBE_EVENT_END_TIME + " text not null, "
+ TALBE_EVENT_NOTE + " text not null"
+");";

我尝试过

SELECT * FROM event WHERE event.start_time = DATE('now');

但是没用..

最佳答案

private static final String CREATE_TABLE_EVENT = "CREATE TABLE "
+ TABLE_EVENT + " ("
+ TABLE_EVENT_ID + " integer primary key autoincrement, "
+ TALBE_EVENT_START_TIME + " text not null, "
+ TALBE_EVENT_END_TIME + " text not null, "
+ TALBE_EVENT_NOTE + " text not null"
+");";

用它替换创建表查询,它应该可以正常工作。

您在注释末尾添加了额外的逗号。

关于android - 如何在 SQLite 中查询等于今天的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48203415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com