Support Topics Documentation Slack YouTube Blog

Search Object with data range


(jempis) #1

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


(Vladimir Upirov) #2

Hi jempis

What “startDate” and “endDate” are?
Timestamp or String?


(Vladimir Upirov) #3

Also you can test your query in the Backendless Console

http://support.backendless.com/public/attachments/a56609603ea2dcc22256bb2875b4c875.png</img>


(jempis) #4

String! you see capture.png


(Vladimir Upirov) #5

wrap dates into single quotes

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

(jempis) #6

now with adding the single quotes response ok, Thank Vladimir


(Vladimir Upirov) #7

Glad to hear that

You are welcome