如何从SQLite中的datetime对象查询日期?
以下是我的尝试:如何从SQLite中的datetime对象查询日期?,sqlite,date,datetime,select,syntax-error,Sqlite,Date,Datetime,Select,Syntax Error,以下是我的尝试: rs=statement.executeQuery(“从geninfo中选择*,其中DeviceTag='”+DeviceTag+“'和timestamp='date('“+fromYear+”-“+”+fromMonth+”-“+fromDay+”);” 它看起来与此类似: select * from geninfo where timestamp='date('2013-07-08')'; 错误是(靠近“2013”:语法错误) 存储的值为“2013-07-08 09:08
rs=statement.executeQuery(“从geninfo中选择*,其中DeviceTag='”+DeviceTag+“'和timestamp='date('“+fromYear+”-“+”+fromMonth+”-“+fromDay+”);”代码>
它看起来与此类似:
select * from geninfo where timestamp='date('2013-07-08')';
错误是(靠近“2013”:语法错误)
存储的值为“2013-07-08 09:08:51”
我想选择某一天的所有数据。另外,将另一列存储为日期对象会更容易吗
不能用单引号括住date
函数,单引号是字符串分隔符。
SQL语句中包含的是字符串date(
、数字2013
、07
、和08
,它们彼此相减,以及字符串)
函数date
将字符串2013-07-08
转换为字符串2013-07-08
。
将其与字符串2013-07-08 09:08:51进行比较将失败。
要从包含时间字段的字符串中删除时间:
SELECT *
FROM geninfo
WHERE DeviceTag = ?
AND date(timestamp) = '2013-07-08'
答案有用吗?