2013-07-08 127 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'