SQLite select rows if timestamp matches today's date

泪湿孤枕 提交于 2019-12-17 20:51:45

问题


I Would like to select all entries from an SQLite table if the entries timestamp matches todays date.

I am querying an SQLite database as follows:

// 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')";

This behavior is the closest I have come but I do not wish to select all entries within the last 24hrs. I only want to select if todays date matches the timestamp.

How can I select only the rows in the table who's timestamp matches todays date.

date format is: 2014-07-05 12:59:35 in the database.


回答1:


does this work?

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



回答2:


For local timezone:

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


来源:https://stackoverflow.com/questions/24591267/sqlite-select-rows-if-timestamp-matches-todays-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!