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 built custom add and subtract date function. but subtract date throws error for .getTime() method
const subtractDate = function(date1, date2){
    const date1Inms = date1.getTime()
    const date2Inms = date2.getTime()
    const subtract = new Date(date2Inms - date1Inms)
    return subtract
}

const addDate = function(date1, days){
    const date1Inms = date1.getTime()
    const dayInms = days*86400000
    const add = new Date(dayInms + date1Inms)
    return new Date(add)
}

my addDate function works correctly but I am getting error "date1.getTime is not a function" for subtractDate . I dont why ? I used getTime() in both but it throws error only in subtract function

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

0

use this, should works.

const subtractDate = (date1, date2) => new Date(date2.getTime() - date.getTime());
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!