选择没有时间的日期

时间:2013-05-20 11:10:36

标签: sql sqlite

我正在使用SQLite,现在我如何选择一个查询,如果我有一个具有此值的时间戳列,例如07:00 06/03/13,但我只想选择时间戳06/03/13的位置。

这是我的查询示例..

select 
    timestamp, pname 
from 
    attendance 
where 
    timestamp between `06/01/13` and `06/10/13`

3 个答案:

答案 0 :(得分:3)

使用date

select timestamp, pname 
from attendance 
where date(timestamp) = '2013-03-06'

答案 1 :(得分:1)

在时间戳列上进行过滤时,您需要此逻辑。

where YourField >= TheStartOfYourRange
and YourField < TheDayAfterTheEndOfYourRange

这相当于使用date()函数的两个答案,但通常会执行得更快。使用where子句中的函数通常会降低生产速度,尤其是在索引字段上。

答案 2 :(得分:0)

SQLite支持函数date,可用于获取时间戳的日期部分。例如:

SELECT * FROM mytable WHERE date(timestamp_col) = '2013-05-20'

有关详细信息,请参阅SQLite date and time functions documentation

相关问题