Solution for "difference between two dates in years javascript"

const date1 = new Date('7/13/2010'); const date2 = new Date('12/15/2010'); console.log(getDifferenceInDays(date1, date2)); console.log(getDifferenceInHours(date1, date2)); console.log(getDifferenceInMinutes(date1, date2)); console.log(getDifferenceInSeconds(date1, date2)); function getDifferenceInDays(date1, date2) { const diffInMs = Math.abs(date2 - date1); return diffInMs / (1000 * 60 * 60 * 24); } function getDifferenceInHours(date1, date2) { const diffInMs = Math.abs(date2 - date1); return diffInMs / (1000 * 60 * 60); } function getDifferenceInMinutes(date1, date2) { const diffInMs = Math.abs(date2 - date1); return diffInMs / (1000 * 60); } function getDifferenceInSeconds(date1, date2) { const diffInMs = Math.abs(date2 - date1); return diffInMs / 1000; }

javascript difference between two dates

const date1 = new Date('7/13/2010'); const date2 = new Date('12/15/2010'); const diffTime = Math.abs(date2 - date1); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); console.log(diffTime + " milliseconds"); console.log(diffDays + " days");

get the difference between two dates js

Similar codes for "difference between two dates in years javascript"


Latest 'Javascript' questions

Added before "difference between two dates in years javascript"