Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
How can I filter documentdb records based on timestamp?

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.

  1. I want to fetch all records which are created in last 1 day.
  2. I want to fetch all records which are created in last 15 days.
  3. I want to fetch all records which are created in last 1 month.
  4. I want to fetch all records which are created in last 1 year.

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
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!