Forum Discussion
Store today's date as a variable
- 2 months ago
You need a code similar to this:
// Get the current date
var currentDate = new Date();
// Array of month names
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
// Get day, month, and year
var day = currentDate.getDate();
var monthIndex = currentDate.getMonth();
var year = currentDate.getFullYear();
// Format the date into a single string
var formattedDate = months[monthIndex] + ' ' + day + ', ' + year;
// Set the variable value in Storyline
GetPlayer().SetVar('currentDate', formattedDate);
You will insert this code into a trigger to run JS.
In Storyline, you need to create a text variable called currentDate and display it on the screen in the desired location.
You need a code similar to this:
// Get the current date
var currentDate = new Date();
// Array of month names
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
// Get day, month, and year
var day = currentDate.getDate();
var monthIndex = currentDate.getMonth();
var year = currentDate.getFullYear();
// Format the date into a single string
var formattedDate = months[monthIndex] + ' ' + day + ', ' + year;
// Set the variable value in Storyline
GetPlayer().SetVar('currentDate', formattedDate);
You will insert this code into a trigger to run JS.
In Storyline, you need to create a text variable called currentDate and display it on the screen in the desired location.
Thanks so much for your reply. Although both sets of code worked for me, this was closest to what I was looking for.