Forum Discussion
PeterGrennan
3 days agoCommunity Member
Javascript Date plus one, plus two etc...
I wonder if any Javascript whizzes can help? I have a very very basic grasp, enough to be able to copy and make some basic edits to get some minor outcomes. I have a slide needing me to calculate a...
- 3 days ago
Try this:
var currentDate = new Date(); var player = GetPlayer(); //1DaysAhead var oneDaysAhead = new Date(currentDate); oneDaysAhead.setDate(currentDate.getDate() + 1); var oneDaysAheadDateString = oneDaysAhead.getDate() + " " + oneDaysAhead.toLocaleString('default', { month: 'short' }) + " " + oneDaysAhead.getFullYear(); player.SetVar("oneDaysAhead", oneDaysAheadDateString); //2DaysAhead var twoDaysAhead = new Date(currentDate); twoDaysAhead.setDate(currentDate.getDate() + 2); var twoDaysAheadDateString = twoDaysAhead.getDate() + " " + twoDaysAhead.toLocaleString('default', { month: 'short' }) + " " + twoDaysAhead.getFullYear(); player.SetVar("twoDaysAhead", twoDaysAheadDateString); // add your other offsets the same way…The issue is that in JavaScript you cannot redeclare the same variable name (player) twice with let inside the same block. Redeclaring let player again causes the script to stop. Also, you don’t need to recalculate currentDate inside each block.
PeterGrennan
3 days agoCommunity Member
Amazing, this worked absolutely perfectly. Thank you so much for your help!