Forum Discussion
MaddieSchroe307
2 years agoCommunity Member
Using Javascript for X Days Ago in MM/DD/YYYY Format
Hello,
I would very much appreciate some help here. I need to have the learner open up this learning and have the current date displayed, as well as some dates prior to it (-10 days, -15 days, -2...
MaddieSchroe307
2 years agoCommunity Member
Solution
For subtracting days:
var player = GetPlayer();
var myNewDate=new Date();
myNewDate.setDate(myNewDate.getDate() - 7);
var month = myNewDate.getMonth() + 1
var day = myNewDate.getDate()
var year = myNewDate.getFullYear()
var dateString=month + "/" + day + "/" + year
player.SetVar("Date",dateString);
- SarahNicholas2 years agoCommunity Member
Thank you, Maddie, for posting your follow up! This is just the solution I was looking for to display a previous date :)
- RoystonDesou7602 years agoCommunity Member
Hello Maddie, Is it possible to modify this code to display the day and month in the double digit format e.g. for 1 Jan 2024 = 01/01/2024?