Forum Discussion
Javascript variable / Current Date
Hi Greg,
You'll want to follow these steps to get the date to show up:
1) Create a Text Variable called todaysDate in Storyline to store the data.
2) Add a text box to the slide with %todaysDate%
as the value. The percent signs indicate that this placeholder should be replaced with the actual value stored in the todaysDate variable. You can put that placeholder anywhere in a text box, it doesn't have to be by itself. So you could have a text box that says Today's date is %todaysDate%
and it would fill in the placeholder with the Variable value. Note that capitalization is important here - if the Variable is called todaysDate then a placeholder like %todaysdate%
won't work.
3) Create a trigger with "Execute JavaScript" as the action, then copy and paste Steve's Javascript code into the Javascript editor in Storyline. (The last line in Steve's code will set a different Variable called "month", so you don't really need it).
let currentTime = new Date();
let month = currentTime.getMonth() + 1;
let day = currentTime.getDate();
let year = currentTime.getFullYear();
// Putting it together
let dateString = month + "/" + day + "/" + year;
//Pushing data to Storyline
let player = GetPlayer();
player.SetVar("todaysDate", dateString);
- GregGilbert-9f312 months agoCommunity Member
HI Chris - This worked perfectly! Thank you so much! Greg