[英]compare date in sql statement
我正在使用Web sql制作警報工具。
我想選擇特定日期發生的所有事件。 當我插入事件時,我將日期插入為具有“ 2011-10-14”格式的日期對象, 我應該在select語句中寫什么以選擇今天發生的所有事件?
我像這樣
cur =new Date();
alert(cur);
db.transaction(function(tx){
tx.executeSql("select NOTE_DESC,NOTE_DATE,NOTE_TIME,ALERT_TIME,NOTES_MORE_DETAILS from NOTES where NOTE_DATE = "+cur+" order by NOTE_TIME asc limit 0,1",[], alert("yes"),onError);
});
我的查詢在其中:
select NOTE_DESC, NOTE_DATE, NOTE_TIME, ALERT_TIME, NOTES_MORE_DETAILS
from NOTES
where NOTE_DATE = "+cur+"
order by NOTE_TIME asc
limit 0,1
但是出現一條錯誤消息,它是“接近十月:語法錯誤”
我應該如何在sql中進行日期比較?
我相信你想要:
NOTE_DATE = '"+cur.getFullYear()+'-'+(cur.getMonth()+1)+'-'+cur.getDate()+"'
注意'
包裝查詢變量的值,並調用cur
date對象的方法構造日期。
更好的是,使用准備好的查詢:
http://www.w3.org/TR/webdatabase/#dom-sqltransaction-executesql
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.