Tuesday, 27 September 2016

Calculate day,month and year using javascript



    <html>
<head>
<title>Date substraction</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--

    var myVar = prompt("Please enter a date: ")

    var udate = Date.parse(myVar);
    var todate = new Date();
    var diffdate = user_date - today_date;

    var years = diffdate / 31536000000;
    var months = (diffdate % 31536000000) / 2628000000;
    var days = ((diffdate % 31536000000) % 2628000000) / 86400000;

    document.write("Number of years: " + Math.floor(years) + "<br>");
    document.write("Number of months: " + Math.floor(months) + "<br>");
    document.write("Number of days: " + Math.floor(days) + "<br>");
//-->
</script>
</body>

</html>

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...