I have seen a few posts about this, but none that I have learnt from.
I need to send a certain date-timestamp to REST API, and it needs to look like this:
2014-01-17 00:00:00.000
So I need two, one for the current months first day, and the current months last day, so something like this:
2014-02-01 00:00:00.000
2014-02-28 00:00:00.000
I have used the following code:
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" : "' +
y + '-' + m + '-' + firstDay + ' 00:00:00.000" , "$lt" : "' +
y + '-' + m + '-' + lastDay + ' 00:00:00.000"}';
But this is the output I get, via dev mode on the browser:
"_createdAt" : {"$gt" : "2014-1-Sat Feb 01 2014 00:00:00 GMT+0000 (GMT) 00:00:00.000" , "$lt" : "2014-1-Fri Feb 28 2014 00:00:00 GMT+0000 (GMT) 00:00:00.000"}}
As you can see, its giving me the correct year, but the month needs to be two digits, and for the last and first day, its giving the full date.
Any ideas how I could manage this ?