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

126
Views
Moment find difference between two date object

I have two dates in my project which are

let a="30-03-1999"
let b="30-03-2022"

Now i need to find the difference between these two dates, so first i am converting them to moment object by

let birthdate = moment(a, 'DD-MM-YYYY')
let licenseDate = moment(b, 'DD-MM-YYYY')

//console.log(birthdate,licenseDate) gives me moment object 

Object { _isAMomentObject: true, _i: "30-03-1950", _f: "DD-MM-YYYY", _isUTC: false, _pf: {…}, _locale: {…}, _d: Date Thu Mar 30 1950 00:00:00 GMT+0530 (India Standard Time), _isValid: true }

upon running the function

var diff = licenseDate.diff(birthdate, 'years')

it returns NaN

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

0

DD-MM-YYYY is not the correct date format, you should try with YYYY-MM-DD, It will work fine

let a="1999-03-30"
let b="2022-03-30"
var date1 = moment(a);
var date2 = moment(b);
console.log(date1.diff(date2, 'years'))

and It will also with DD-MM-YYYY

let a="30-03-1999"
let b="30-03-2022"
var date1 = moment(a, 'DD-MM-YYYY');
var date2 = moment(b, 'DD-MM-YYYY');
console.log(date1.diff(date2, '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!