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

462
Views
currentDate.diff() no es un error de función en moment.js
const currentDate = moment(new Date()).format('DD/MM/YYYY'); //03/01/2022 var days_diff = currentDate.diff(returnDate,'days'); // returnDate = 08/12/2021 console.log(days_diff)

Error: TypeError no capturado: currentDate.diff no es una función

Estoy tratando de obtener la diferencia de días entre la fecha actual y la fecha de regreso, pero me da un error currentDate.diff no es una función

Por favor solucione este error.

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

0

Esto se debe a que .format('DD/MM/YYYY') genera una cadena, que no tendrá las funciones Moment disponibles. En su lugar haz esto:

 const currentDate = moment(new Date('03/01/2022')); const returnDate = moment(new Date('08/12/2021')); var days_diff = currentDate.diff(returnDate,'days'); console.log(days_diff)

Mantenga el objeto Moment Date en todas sus operaciones. Formatearlo temprano solo lo convierte en una cadena.

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!