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

182
Views
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 answers
Answer question

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 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!