Javascript to show a date 1 week from now

Hi there
can one of you lovely people help me write a javascript to return a date 1 week from now?  

I have been playing with the following script to little success;

function fixDigit(val){
return val.toString().length === 1 ? "0" + val : val;
}

var player = GetPlayer();

var d = new Date();

var days = ["Sun","Mon","Tue","Wed","Thur","Fri","Sat"];

var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];

var year = d.getFullYear();

var sInfo = d.getDate() + " " + months[d.getMonth()] + " " + year;

player.SetVar("NextWeekFull",sInfo);

I need it to return in date format "10 Jul 2020" and in full month "10 July 2020".

 

TIA :-) 

2 Replies
Joseph Francis

Using this post on StackOverflow as a starting point, I threw this together:

var player = GetPlayer();
var sInfo = new Date();

sInfo.setDate(sInfo.getDate() + 7);

var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

var mm = sInfo.getMonth();
var strMonth = arrMonths[mm];

var dd = sInfo.getDate();
var yyyy = sInfo.getFullYear();
var sInfo = dd + " " + strMonth + " " + yyyy;

player.SetVar("NextWeekFull", sInfo);

To display a day's name like you have in your code, use a variation of the process used to retrieve the name of the month:

var arrDays = new Array("Sun","Mon","Tue","Wed","Thur","Fri","Sat");
var dd = sInfo.getDate();
var strDay = arrDays[dd];