What you basically want to create two dates:
date 0: 0: 0 timesdate+1day at 0: 0: 0 times
Then do a search:
query.greaterThanOrEqualTo('createdAt', date); query.lessThan('createAt', datePlusOne);
This effectively gives you the range dateT0: 0: 0 - dateT23: 59: 59.99999 inclusive, but in a safe way
If you want to use pure JavaScript:
// assuming date is the date/time to start from date.setHours(0, 0, 0, 0); // hours/min/sec/ms cleared var datePlusOne = new Date(date); datePlusOne.setDate(datePlusOne.getDate() + 1);
You can also use the minutes archive to make your code easier to read / maintain. This library is also used on the server side at parse.com, although this is an older version.
m1 = new moment(date); m1.startOf('day'); m2 = new moment(m1); m2.add(1, 'day');
Complete solution using moments:
var d = new Date(); var query = new Parse.Query("TableName"); var start = new moment(d); start.startOf('day'); // from the start of the date (inclusive) query.greaterThanOrEqualTo('createdAt', start.toDate()); var finish = new moment(start); finish.add(1, 'day'); // till the start of tomorrow (non-inclusive) query.lessThan('createdAt', finish.toDate()); query.find.then(function(results) { // use results });
source share