Backendless Support
 
Answered

Search Object with data range

Hi all,

i want to have an api in my service that return a list of objects created in a time range.

I have create this method in the cloud code js (the model is 'Objects'):

----

/**

*

* @param {DateTime} startDate

* @param {DateTime} endDate

* @returns {Promise.<void>}

*/

getObjectsByRange(startDate, endDate) {

var whereClause = "created at or after "+startDate + " and created at or before "+endDate;

var queryBuilder = Backendless.DataQueryBuilder.create().setWhereClause( whereClause );

var result = Backendless.Data.of( Objects ).find( queryBuilder );

return result;

}

------

but when i tested with "Api Service", return this error "400 - Invalid where clause (1017)"

What am i doing wrong?

Thank

GF

Best Answer
photo

wrap dates into single quotes

  1. created at or after '01/04/2018 15:50:42' and created at or before '01/05/2018 12:40:33'

Leave a Comment

Comments (6)

photo
1

Hi jempis

What "startDate" and "endDate" are?

Timestamp or String?

photo
1

String! you see capture.png

photo
2

wrap dates into single quotes

  1. created at or after '01/04/2018 15:50:42' and created at or before '01/05/2018 12:40:33'

photo
1

now with adding the single quotes response ok, Thank Vladimir

photo
1

Glad to hear that

You are welcome

photo
photo
1

Also you can test your query in the Backendless Console

a56609603ea2dcc22256bb2875b4c875