Get year, month and day from date difference : Date Calculation : Date JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Date » Date Calculation »

 

Get year, month and day from date difference

















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

var myVar = prompt("Enter a future date: ")

var user_date = Date.parse(myVar);
var today_date = new Date();
var diff_date =  user_date - today_date;

var num_years = diff_date/31536000000;
var num_months = (diff_date % 31536000000)/2628000000;
var num_days = ((diff_date % 315360000002628000000)/86400000;

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







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Date
» Date Calculation