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

206
Visualizações
How to check if current date is between two dates in javascript

I'm trying to make a Livestream feature in my project, I have an array of programs (videos), every video has startDate and endDate. I should run every video when its time has come.

const programs = [
    { video: "URL", startDate: 1644405993, endDate: 1644406032 },
    { video: "URL", startDate: 1644405993, endDate: 1644406032 },
    { video: "URL", startDate: 1644405993, endDate: 1644406032 },
    { video: "URL", startDate: 1644405993, endDate: 1644406032 }
];
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can get a new date and compare it against your stored dates (though you appear to have not stored the dates as correct date-timestamps). The item you are after is the one with a startDate less than current and end endDate greater than current. This will also give an empty array if no matches found - so you will need to have a check against the returned matches length.

const programs = [
    { video: "URL1", startDate: 1644492517146, endDate: 1644492517446 },
    { video: "URL2", startDate: 1644492517726, endDate: 1644492517646 },
    { video: "URL3", startDate: 1644492507746, endDate: 1644492517546 },
    { video: "URL4", startDate: 1644492517746, endDate: 16474492519746 }
];

const now =new Date().getTime(); // gives similar to 1644492517146

const currentProgram = programs.filter(
  p => new Date(p.startDate) < now && new Date(p.endDate) > now
);

console.log(currentProgram) // gives [{ video: "URL4", startDate: 1644492517746, endDate: 16474492519746 }]

about 4 years ago · Juan Pablo Isaza Relatório

0

try this

export const checkTime = (startDate, endDate) => {// startDate= 1644405993, endDate = 1644406032
const now = new Date()
const bookingStartDate = new Date(startDate) // use this step to convert your date if its stored in a different format
const bookingEndDate = new Date(endDate) // use this step to convert your date if its stored in a different format
return now.getTime() > bookingStartDate.getTime() && now.getTime() < bookingEndDate.getTime()

}

about 4 years ago · Juan Pablo Isaza Relatório

0

You can check by calling this function.

function compareDates(startDate,endDate){
  let current=new Date();
  return startDate>=current && endDate<=current;
}
about 4 years ago · Juan Pablo Isaza 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