2014-09-19 196 views
0

調用從Node/JS應用程序接受'datetime'參數的MYSQL存儲過程似乎沒有正常工作。節點/ JavaScript日期時間和MySQL

從sql中調用MySQL過程工作正常,但不是來自JS。這裏是我的僞代碼:

//procedure 
Proc(IN startDate datetime) {... select * from tbl where start = Date(datetime) ..} 

//this works ok from sql 
Call Proc (NOW()) 

//From Node/JS, these don't seem to get the correct results 
connection.query(call proc(new Date()) 
connection.query(call proc(getFormattedDate(new Date()) 

編輯:我正在使用此函數返回格式化日期。

var getFormattedDate = function(Date_toYMD) { 
Date.prototype.toYMD = Date_toYMD; 

    var year, month, day; 
    year = String(Date_toYMD.getFullYear()); 
    month = String(Date_toYMD.getMonth() + 1); 
    if (month.length == 1) { 
     month = "0" + month; 
    } 
    day = String(Date_toYMD.getDate()); 
    if (day.length == 1) { 
     day = "0" + day; 
    } 
    return year + "-" + month + "-" + day; 

};

回答

0

今天的日期是像這樣在JavaScript:

var dt = new Date; 
console.log(dt.getFullYear()+'-'+(++dt.getMonth())+'-'+dt.getDate()); 
+0

那是什麼我有。我上面的代碼是僞的,但我可以使用這個函數,它與你的相同var getFormattedDate = function(Date_toYMD){Date.prototype.toYMD = Date_toYMD; VAR年,月,日; year = String(Date_toYMD.getFullYear()); month = String(Date_toYMD.getMonth()+ 1); (month.length == 1){ month =「0」+ month; } day = String(Date_toYMD.getDate()); (day.length == 1){ day =「0」+ day; if(day.length == 1) } return year +「 - 」+ month +「 - 」+ day; }; – user1529412 2014-09-19 22:34:22