我正在使用SQLite,现在如何选择一个查询,如果我有一个时间戳列有这个值,例如07:00 06/03/13
但我只想选择时间戳06/03/13
。选择没有时间的日期
这是我的我的查询的例子..
select
timestamp, pname
from
attendance
where
timestamp between `06/01/13` and `06/10/13`
我正在使用SQLite,现在如何选择一个查询,如果我有一个时间戳列有这个值,例如07:00 06/03/13
但我只想选择时间戳06/03/13
。选择没有时间的日期
这是我的我的查询的例子..
select
timestamp, pname
from
attendance
where
timestamp between `06/01/13` and `06/10/13`
使用date
select timestamp, pname
from attendance
where date(timestamp) = '2013-03-06'
SQLite的支持功能date
,它可以被用来获得时间戳的日期部分。例如:
SELECT * FROM mytable WHERE date(timestamp_col) = '2013-05-20'
有关更多信息,请参阅SQLite date and time functions documentation。
在时间戳列上过滤时,您需要此逻辑。
where YourField >= TheStartOfYourRange
and YourField < TheDayAfterTheEndOfYourRange
这相当于使用date()函数的两个答案,但通常会执行得更快。在where子句中使用函数通常会减慢生产速度,特别是在索引字段上。
使用simpleDateFormat.parse解析它为一个字符串 –