See the similarity to the other posts now?
Javascript
function padLeft(arg) {
if (arg < 10) {
arg = '0' + arg;
}
return arg;
}
function myFormat(dateObject) {
return [
dateObject.getFullYear(),
padLeft(dateObject.getMonth() + 1),
padLeft(dateObject.getDate())
].join('-') + ' 00:00:00.000';
}
var date = new Date(),
y = date.getFullYear(),
m = date.getMonth(),
firstDay = new Date(y, m, 1),
lastDay = new Date(y, m + 1, 0),
querydate = '"_createdAt" : {"$gt" : "' +
myFormat(firstDay) + ' , "$lt" : "' +
myFormat(lastDay) + '"}';
console.log(querydate);
Output
"_createdAt" : {"$gt" : "2014-02-01 00:00:00.000 , "$lt" : "2014-02-28 00:00:00.000"}
On jsFiddle