Displaying today's date and a date some days before - Storyline 360

Feb 07, 2020

Hi

I'm trying to crate a variable that takes the actual date from the system minus a number of days and displays a proper date. 

I've found this Javascript for displaying the system date from old posts but don't know how create a date some days previous. I have no experience with Javascript

var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear();
var player = GetPlayer();
var newName = day + "/" + month + "/" +year
player.SetVar("DateValue", newName)

4 Replies
Bob Dobbs

I don't have Storyline installed anymore, but this should work:

// GET PLAYER OBJECT
var player = GetPlayer();
// MAKE NEW DATE OBJECTS
var currentDate = new Date();
var priorDate = new Date();
// MAKE CURRENT DAY VALUES
var currentday = currentDate.getDate();
var currentmonth = currentDate.getMonth() + 1;
var currentyear = currentDate.getFullYear();
// MAKE PRIOR DAY
var daysAgo = 9;
priorDate.setDate(priorDate.getDate() - daysAgo);
var priorday = priorDate.getDate();
var priormonth = priorDate.getMonth() + 1;
var prioryear = priorDate.getFullYear();
// MAKE STRINGS FOR DISPLAY
var currentDate_str = currentday + "/" + currentmonth + "/" + currentyear;
var priorDate_str = priorday + "/" + priormonth + "/" + prioryear;
// SET PLAYER VALUES
player.SetVar("DateValue", currentDate_str);
player.SetVar("PriorDateValue", priorDate_str);

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