javascriptreact-nativeparse-platformback4appparse-javascript-sdk

Query by date with JS in Back4App


I've got dates in my Back4App backend with times defaulting to midnight (start of day) e.g.

5 May 2019 at 00:00:00 UTC

I'm trying to use this date as a filter in my query. Without the filter, the object is retrieved with this date in the following format

"departureDate": Object {
      "__type": "Date",
      "iso": "2019-05-04T00:00:00.000Z",
    }

While the bulti-in back4App dates are showing as follows:

"createdAt": "2019-03-09T13:28:10.262Z"

In my query I use the following criteria:

const todaysDate = new Date().setHours(0,0,0,0);
const InboundTrain = Parse.Object.extend('Inbound');
const query = new Parse.Query(Inbound);
query.greaterThanOrEqualTo("departureDate", todaysDate);

However, the query returns nothing. I've run out of ideas, anyone's seen this behaviour before?


Solution

  • Try just to change this line here:

    const todaysDate = new Date(new Date().setHours(0,0,0,0));