Storyline

Pull Current Date in Storyline Using JavaScript

Using JavaScript inside of Articulate Storyline gives you extended features and capabilities. You can create custom animations, detect the user's operating system, and more. One of the cool things you can do is detect the current date and time the user is taking your course and then change content based on the date.

In this example, I walk you through how to pull the date and format it to display to the user. I also show you how to isolate the month and then change a state of a Storyline object depending on the month. So you can modify things in your training like backgrounds or variable information to personalize content based on when the learner is taking the course. All it takes is the simple code snippet below and some logic inside Storyline. Check it out.

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);
player.SetVar("month", month);
          
Jeff Batt
15 Nov, 2022