Calculate days and weeks from date in javascript

1
2
3
4
5
6
7
8
9
var lastMestrualDate = document.getElementById('LastMestrualDate').value;
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
const firstDate = new Date(lastMestrualDate);
const secondDate = new Date();

const diffDays = Math.round(Math.abs((firstDate - secondDate) / oneDay));
var weeks = diffDays / 7;
var days = diffDays % 7;
document.getElementById('EGA').value = parseInt(weeks)+' Weeks' +' '+ days +' Days';

Post a Comment

0 Comments