Forum Discussion
OnboardingTeam
3 years agoCommunity Member
Show a date X number of days before today's date on Storyline - is this possible?
I have figured out how to pull today's date using Javascript. However, I want to generate a date that is X amount of days before today's date. For example, today shows as 30/08/2023. I want to show ...
TinaGlynn-59324
3 years agoCommunity Member
I'm also looking for Javascript to show 15 days prior to today's date in the format of MM/DD/YYYY, but everything I've tried so far in the wrong format or shows a negative number for the date. The previous reply shows it in a document, but I need to use it as a variable in Storyline. I'm new to Javascript, so I'm not sure what changes need to be made.
- JordanBest3 years agoCommunity Member
Hi Tina, you can try this code:
var currentDate = new Date();
var fifteenDaysAgo = new Date(currentDate);
fifteenDaysAgo.setDate(currentDate.getDate() - 15);
// Format the date
var formattedDate = (fifteenDaysAgo.getMonth() + 1) + '/' + fifteenDaysAgo.getDate() + '/' + fifteenDaysAgo.getFullYear();
var player = GetPlayer();
player.SetVar("YourVariableName", formattedDate);
// you'll need a text variable titled "YourVariableName" in SL- TinaGlynn-593243 years agoCommunity Member
Jordan,
That worked perfectly. Thank you!
Related Content
- 7 months ago
- 2 years ago
- 8 months ago
- 8 months ago
- 9 months ago