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

183
Visualizações
Knowing the number of Days between 2 Dates in HTML/JScript

I'm stuck on this activity of mine where we need to subtract the inputs of two dates: It keeps saying "Uncaught TypeError: Cannot read properties of null (reading 'value')" and I'm using CodePen.io as the IDE

HTML:

From Date: 
<input id="start" name="trip-start"> 
<p>
To Date:
<input id="end" name="trip-end"><p>
<button id="Subtract" onclick="document.getElementById('demo').innerText = 
subtract(document.getElementById('Difference_In_Days').value)" > Show Me Difference </button> 
<p>
<input id="demo">

JScript:

function subtract(txt) 
{
var date1 = txt.match(/^\d?\d\/(\d?\d)\/\d{4}$/);
return date1? !!Date.parse(txt) && new Date(txt).getDate()==date1[1] : false;
var date2 = txt.match(/^\d?\d\/(\d?\d)\/\d{4}$/);
return date2? !!Date.parse(txt) && new Date(txt).getDate()==date2[1] : false;

var Difference_In_Time = date2.getTime() - date1.getTime();
var Difference_In_Days = String(Difference_In_Time());
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
const firstDate = new Date(2008, 1, 12);
const secondDate = new Date(2008, 1, 22);

const diffDays = Math.round(Math.abs((firstDate - secondDate) / oneDay));

console.log(diffDays)

The question is already answered in

How do I get the number of days between two dates in JavaScript?

and

How to calculate the number of days between two dates?

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