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

155
Views
I want to make if condition between two dates difference

const today = new Date();
var date2 = new Date("10/29/2021");

var Difference_In_Time = date2.getTime() - today.getTime();

var Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24);

document.write(
  "Total number of days between dates  <br>" +
  today +
  "<br> and <br>" +
  date2 +
  " is: <br> " +
  Difference_In_Days
);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First explain what is the issue.

But if you just want one of the correct way of getting date differences. You should look below code.

And don't subtract bigger date from smaller one. If you want to do like that you must get its absolute value. You should do like below code.

const date1 = new Date('9/20/2021');
const date2 = new Date();
const diffTimeInMilliseconds = Math.abs(date2 - date1); // this gives time difference in milliseconds
const diffDays = Math.floor(diffTimeInMilliseconds / (1000 * 60 * 60 * 24)) // 1 second = 1000 ms, 1 minute = 60 s, 1 hour = 60 m, 1 day = 24 h; 
console.log(diffTimeInMilliseconds + " milliseconds");
console.log(diffDays + " days");

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!