I am using documentdb database since long,
thus it has lots of records/documents in collections,
No to simplify it I want to fetch records/documents based on timestamp.
I have tried to rite query like this but its not working.
var curDate = new Date().getTime();
SELECT * FROM r WHERE r._ts >= @curDate AND r.studentId=@studentId
new Date().getTime() docs say
A number representing the milliseconds elapsed between 1 January 1970 00:00:00 UTC and the given date.
_ts docs say
a number representing the number of elapsed seconds since January 1, 1970
So you are comparing milliseconds to seconds, which won't yield any results.
You need to divide the first value by 1000 before you compare it to the second value. And, of course, you need to subtract 1 day, 1 month or whatever value you need, e.g.
var twoDaysAgo = new Date();
twoDaysAgo.setDate(d.getDate() - 2);
var threshold = twoDaysAgo.getTime() / 1000;
SELECT * FROM r WHERE r._ts >= @threshold AND r.studentId=@studentId