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
Joanna Kurpiewska

Michael Hinze said:

Joanna Kurpiewska said:

Hi Scott

Thanks for sharing the idea, but I've downloaded the .story file and no data are displayed :/


To avoid having the JavaScript blocked by your browser's security settings, try publishing for CD or publish for Web, upload the content to a server and then test again.


@Michael

Thanks Works fine.

This discussion is closed. You can start a new discussion or contact Articulate Support.