0

我正在尝试在语法下使用它,但它不起作用。请帮助

var acccID = "acc";
    var date = (new Date().getMonth()+1)+"/"+new Date().getDate()+"/"+new Date().getFullYear();
    var dt1 = (new Date().getMonth()+1)+"/1/"+new Date().getFullYear();
    var dt2 = (new Date().getMonth()+1)+"/31/"+new Date().getFullYear();
    var cr = 5000;

$.mobile.eazydb.transaction(function(tx){
            tx.executeSql('INSERT INTO Ledger (Ledger_Account_ID, Ledger_Date, Ledger_Credit, Ledger_Memo)\
                    VALUES("'+acccID+'", "'+date+'", "'+cr+'", "Opening Balanace : Manish")', [],
                function(tx) { alert('ledger entry successfull.');  }, function(err) {   alert('error in inserted : '+err);  
            });
        });

$.mobile.eazydb.transaction(function(tx){
            tx.executeSql('SELECT * FROM Ledger WHERE Ledger_Date BETWEEN "'+dt1+'" AND "'+dt2+'" ORDER BY Ledger_Date DESC, Ledger_Credit', [],
                function(tx, rs){
                    if(rs.rows.length == 0) {
                        alert('No entries found');
                    } else {
                        for(var i = 0; i<rs.rows.length; i++) {
                            var row = rs.rows.item(i);
                            alert('A/C id : '+row['Ledger_Account_ID']+'\n'+
                                  'Ledger Date : '+row['Ledger_Date']+'\n'+
                                  'Ledger Credit : '+row['Ledger_Credit']+'\n'+
                                  'Ledger Memo : '+row['Ledger_Memo']);
                        }
                    }
            });
        });

它只会发出警报No entries found

4

3 回答 3

0

您可以使用普通运算符:

if(currentDate > minDate  && currentDate < maxDate){
// Do stuff
}
于 2013-07-08T07:56:40.503 回答
0

这不是解决您的问题的方法,而是值得注意的事情。您的日期字符串是静态定义的,因此它们与任何其他语言环境都不兼容。在您的查询中使用 ISO 日期格式,因为数据库很可能支持它们并且允许本地化:

var acccID = "acc",
    now = new Date(),
    dstrNow = now.toISOString(),
    cr = 5000,
    dtStart, dtEnd,
    dstrStart, dstrEnd;

dtStart = new Date();
dtStart.setDate(1);
dstrStart = dtStart.toISOString();

dtEnd = new Date();
dtEnd.setMonth(dtEnd.getMonth() + 1);
dtEnd.setDate(-1);
dstrEnd = dtEnd.toISOString();

用 dstrStart 和 dstrEnd 相应地替换您的 dt1 和 dt2 值。

于 2013-07-08T08:10:52.457 回答
0

错误在此查询SELECT * FROM Ledger WHERE Ledger_Date BETWEEN "'+dt1+'" AND "'+dt2+'" ORDER BY Ledger_Date DESC, Ledger_Credit中。如果要在 SQL 中选择日期范围,日期必须为 yyyy-mm-dd 或 yyyy/mm/dd 格式。因此,请检查 dt1 和 dt2 变量是否采用上述格式,打印上述选择查询并检查日期范围参数。例如,您的查询可能看起来像

SELECT * FROM Ledger WHERE Ledger_Date BETWEEN "2013-10-01" AND "2014-11-01" ORDER BY Ledger_Date DESC
于 2013-07-08T09:06:01.783 回答