2013-07-08 126 views
0

这里是我的尝试:如何从SQLite中的日期时间对象查询日期?

rs = statement.executeQuery("select * from geninfo where DeviceTag='" + deviceTag + "' and timestamp='date('"+fromYear + "-" +fromMonth + "-" + fromDay + "')';");

这将类似于此:

select * from geninfo where timestamp='date('2013-07-08')'; 

的错误是(near "2013": syntax error)

存储的值是“2013年7月8日09: 08:51“

我想选择某一天的所有数据。另外,将另一列存储为日期对象会更容易吗?

+0

确实[这](http://stackoverflow.com/questions/1975737/sqlite-datetime-comparison)的回答帮助? – n0741337

回答

0
  1. 您不得将date函数用单引号括起来,它们是字符串分隔符。 SQL语句中的内容是字符串date(,数字2013,0708(它们彼此相减)以及字符串)
  2. 功能date字符串2013-07-08转换成字符串2013-07-08。 将其与字符串2013-07-08 09:08:51比较将会失败。 您希望从有时间字段中的字符串中去除的时间:

    SELECT * 
    FROM geninfo 
    WHERE DeviceTag = ? 
        AND date(timestamp) = '2013-07-08'