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

162
Views
how to find difference between two different formatted dates in year

My backend is sending me the date-time stamp of a document and I want to calculate the age of that document in frontend I am using moment but don't know how to calculate the difference between them

var TodaysDate = new Date();  //Mon May 09 2022 22:52:42 GMT+0530 (India Standard Time)
var DateFromServer = Entity;  // 2021-05-02T13:18:00.000Z

i want Answer in years like 3.4 years

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

0

With moment you can do it like this

const TodaysDate = moment('Mon May 09 2022 22:52:42 GMT+0530');
const DateFromServer = moment('2021-05-02T13:18:00.000Z');

const diff = TodaysDate.diff(DateFromServer, 'year', true);

console.log(diff.toFixed(2) + " Years");
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!