I found in the net the following script. It can help you. <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; document.write(diff_date); //--> </script> </body> </html>
Try this sample code, i think it helps you: <head> <script> function WriteDateTwoWeeksAgo () { var date = new Date (); var timeInMillisec = date.getTime (); // the milliseconds elapsed since 01 January, 1970 00:00:00 UTC timeInMillisec -= 14 * 24 * 60 * 60 * 1000; // 14 days in milliseconds date.setTime (timeInMillisec); var twoWeeksAgoSpan = document.getElementById ("twoWeeksAgo"); twoWeeksAgoSpan.innerHTML = date.toLocaleString (); } </script> </head> <body onload="WriteDateTwoWeeksAgo ()"> <span id="twoWeeksAgo"></span> </body> Code (markup):