Storyline - Retrieve and Display Formatted Date
Jul 08, 2014
You can call a JavaScript on any trigger in Storyline to retrieve the current date, split it into day, month, year, and set variables using the following code.
__________________________________
var player = GetPlayer();
// retrieve the current full date from the computer
var SystemDate = new Date();
// create an array to convert day number into day text
var weekdays = new Array(7);
weekdays[0]= "Sun";
weekdays[1] = "Mon";
weekdays[2] = "Tue";
weekdays[3] = "Wed";
weekdays[4] = "Thu";
weekdays[5] = "Fri";
weekdays[6] = "Sat";
// create an array to convert month number into month text
var months = new Array(12);
months[0]= "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";
// set Javascript variables from above
var weekDay = weekdays[SystemDate.getDay()];
var dateDay = SystemDate.getDate();
var dateMonth = months[SystemDate.getMonth()];
var dateYear = SystemDate.getFullYear();
// set variables in Storyline to variables from Javascript above
player.SetVar("SystemDate", SystemDate);
player.SetVar("weekDay", weekDay);
player.SetVar("dateDay", dateDay);
player.SetVar("dateMonth", dateMonth);
player.SetVar("dateYear", dateYear);
__________________________________
Sample file attached.
5 Replies
Hi Scott
Thanks for sharing the idea, but I've downloaded the .story file and no data are displayed :/
Within the JS, "weekday" in the formattedDate var should be "weekDay".
Below is the file with the adjusted JS line that should be working when published and viewed.
Thanks Josh,
I was just trying to track that down. That line was a last minute addition to the file and I guess I didn't test it first.
More eyes are definitely better.
@Michael
Thanks Works fine.
This discussion is closed. You can start a new discussion or contact Articulate Support.