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

160
Visualizações
uanble to compare times before and after midnight

I'm trying to compare times before and after midnight however after midnight the check fails.

What I want to do is check if the time is between 11 pm and 6 am.

Here is what I'm working with

// Hours
const start =  23 * 60 + 0;
const end   =   6 * 60 + 0;

// Get todays date 11pm
const now = new Date();

// Check tomorrow for 6am
const nextDay = new Date(now.getTime() + 86400000); 

const time_today = now.getHours() * 60 + now.getMinutes();
const time_tomorrow = nextDay.getHours() * 60 + nextDay.getMinutes();

if (time_today >= start && time_tomorrow < end) {
    return interaction.reply({content: `You cannot do that until 6am.`, ephemeral: true})
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since you have now.getHours(), why not just check if it's between 11pm and 6 am?

const hours = now.getHours();
if (hours < 6 || hours==23){
  return interaction.reply({content: `You cannot do that until 6am.`, ephemeral: true});
}
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