forked from 0xvashishth/CalcHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
27 lines (20 loc) · 1.08 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
let currDate = new Date();
let currYear = currDate.getFullYear().toString();
let currMonth = (currDate.getMonth() + 1) < 10 ? "0" + (currDate.getMonth() + 1).toString() : (currDate.getMonth() + 1).toString();
let currDay = (currDate.getDate() < 10 ? "0" + currDate.getDate().toString() : currDate.toString());
console.log(currDate);
//setting max date value
document.getElementById("birthday").max = currYear + "-" + currMonth + "-" + currDay;
//date format displayed is DD/MM/YYYY
document.getElementById("date1").innerHTML = currDay;
//function to calculate age from date of birth
function getDOB() {
let dob = document.getElementById("birthday").value;
// date format displayed is MM/DD/YYYY
let differnceDate = new Date(currDate - new Date(dob));
let years = differnceDate.toISOString().slice(0, 4) - 1970;
let months = differnceDate.getMonth();
let days = differnceDate.getDate();
let wishText = `<div class = "dob"><center>YOUR AGE </center></div>`;
document.getElementById("text").innerHTML = wishText + years + " Years " + months + " Months " + days + " Days";
}