Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Calculate The Number Of Days, Months Or Years Between Two Dates Using Javascript
WhatsApp
Mohd Arif
Jul 30
2016
3.9
k
0
0
<html>
<head>
<title> Calculate The Number Of Days, Months Or Years Between Two Dates Using Javascript </title>
</head>
<body>
<div> Date of Birth <input type=
"text"
id=
"DOB"
name=
"DOB"
placeholder=
"dd/mm/yyyy "
></input> <br/> Current Date<input type=
"text"
name=
"Date"
id=
"Date"
placeholder=
"dd/mm/yyyy"
></input> <br/> <button type=
"Button"
onclick=
"age()"
>Calculate</button >
</div>
</body>
<script type=
"text/javascript"
>
function
age() {
debugger
;
var
birthdate = document.getElementById(
'DOB'
).value;
// in "dd/MM/yyyy" format
var
senddate = document.getElementById(
'Date'
).value;
// in "dd/MM/yyyy" format
var
x = birthdate.split(
"/"
);
var
y = senddate.split(
"/"
);
var
bdays = x[0];
var
bmonths = x[1];
var
byear = x[2];
//alert(bdays);
var
sdays = y[0];
var
smonths = y[1];
var
syear = y[2];
//alert(sdays);
if
(sdays < bdays) {
sdays = parseInt(sdays) + 30;
smonths = parseInt(smonths) - 1;
//alert(sdays);
var
fdays = sdays - bdays;
//alert(fdays);
}
else
{
var
fdays = sdays - bdays;
}
if
(smonths < bmonths) {
smonths = parseInt(smonths) + 12;
syear = syear - 1;
var
fmonths = smonths - bmonths;
}
else
{
var
fmonths = smonths - bmonths;
}
var
fyear = syear - byear;
alert(fyear +
' years '
+ fmonths +
' months '
+ fdays +
' days'
);
}
</script>
</html>
// This is just a sample script. Paste your real code (javascript or HTML) here.
if
(
'this_is'
==/an_example/){of_beautifier();}
else
{
var
a=b?(c%d):e[f];}
Calculate The Number Of Days
Months Or Years Between Two Dates
Javascript
Up Next
Calculate The Number Of Days, Months Or Years Between Two Dates Using Javascript