Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda