Setting variable to adjust dates in Storyline

Apr 23, 2015

I am working on a course that deals with dates in Storyline. I want the Learner to be able to say that today's date is X. Then within the text of the course, I want to show a date that is 8 months away. 

For example, the Learner inputs today's date is 04/23/15. I want to have the presentation to show a scenario that is 8 months away - the date 12/23/15. 

This is essential for me to create an e-learning course that will not require monthly updates. Is there a way to make this happen with variables?

10 Replies
Brandon Harper

This helped :-) Thank you to both of you. the links together provided  me with enough information to piece it all together. The final code is:

var currentTime = new Date()
var month = currentTime.getMonth() + 9
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var dateString=month + "/" + day + "/" + year
var player = GetPlayer();
player.SetVar("SystemDate",dateString);

This line : var month = currentTime.getMonth() + 9 is what really threw me for a loop. Although I am trying to find 8 months from today, the 9 is used. At a 0 value, it looks at the prior month, 1 is the current month, etc. 

in the Storyline project, I can pull the variable in my text by using %SystemDate%. 

Thank you again! Hopefully this information posted back with my solution will help others. 

Jackson Hamner

This worked for me, so that it loops over into the next year if the date goes past december:

var currentTime = new Date();
var year = currentTime.getFullYear();
var day = currentTime.getDate();
var month = currentTime.getMonth();
if((month + 9) > 11){
month = (month + 9) - 11;
year+=1;
}
var dateString=month + "/" + day + "/" + year;
var player = GetPlayer();
player.SetVar("SystemDate",dateString);

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