-3

I want to know if it is possible to modify the date below to read 2 weeks ahead, instead of reading the actual date?

<script language="JavaScript">
  var now = new Date();
  var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
  var monNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  document.write(" " + dayNames[now.getDay()] + " " + monNames[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear());
</script>
    
<!--End Date Script-->
Ramsharan
  • 2,054
  • 2
  • 22
  • 26
bobos
  • 3
  • 3

1 Answers1

0
var daysToAdd = 14; 
var myDate = new Date(new Date().getTime()+(daysToAdd * 24 * 60 * 60 *1000));

var output = [
  dayNames[myDate.getDay()],
  monNames[myDate.getMonth()],
  myDate.getDate(),
].join(' ') + ', ' + myDate.getFullYear(); // "Thursday April 23, 2015"

DEMO

Andy
  • 61,948
  • 13
  • 68
  • 95
  • If the demo works, it's most likely a problem in your own code @bobos – unbindall Apr 09 '15 at 23:31
  • @Andy, please could you demonstrate how it should be on the HTML file. Please! – bobos Apr 10 '15 at 14:09
  • @bobos, what HTML file? What are you asking? – Andy Apr 10 '15 at 14:14
  • @Andy I am a newbie and would like you to demonstrate in full how it should appear on the HTML file where the code is intended to be used. Thank – bobos Apr 10 '15 at 15:48
  • @Andy, For reference, you can see the answer to this question. http://stackoverflow.com/questions/29543303/allow-certain-characters-in-textbox at the point where the teacher wrote "So your whole page should look like:" – bobos Apr 10 '15 at 15:54
  • It goes within `` tags. What you do with it after that is entirely up to you. I can't, and don't have the time, to give you a tutorial on HTML/JavaScript, I'm sorry. – Andy Apr 10 '15 at 16:22