Time & Date Variables in Storyline

Aug 22, 2013

Hi All,


I saw the posting to help the discussion regarding insert the current date into the course using a javascript. However, it puts the date in MM/DD/YYYY format. How would you go about putting the date into a format like,"Thursday, August 22"?


Also, how would you write a javascript to show the current time? I don't need a timer, but an actual clock. I found a few javascripts online (http://www.quackit.com/javascript/tutorial/javascript_date_and_time.cfm) but they didn't work. I think its because they are not articulate specific.

I am completely new to java so I have no idea how to write them from scratch. Any help is appreciated!!!

57 Replies
Michael Hinze
Gene Rukavina

This exciting because I am trying to figure out if I can add the current date to a certificate of course completion. I am very new to Storyline, so not sure how to insert the code above into Storyline 2?

You can cut&paste JS code into an Execute Javascript trigger. Make sure that you also create the Storyline variables that are used in the JS code.

Christie Pollick

Hello, all!

I just thought I should stop in to note for anyone who is considering using JS as an option, unfortunately, we are not able to provide support for JavaScript coding. Luckily, we have lots of community members who are more than willing to share their expertise to assist!

And for those who'd like to review it, here is a sheet on JavaScript Best Practices you may want to keep handy. :)

Alicia Blitz

Hi Nuno, thanks for sharing.

I am having troubles getting the script to work for me. I am actually wanting to modify it a bit too.  

I am creating a TV screen and want to have a guide option. I want to replicate the day_date format on the left and also want the times across the top be relative to the current time. Here's a sample of wat I am trying to replicate:

I included a file below.

Nuno Cardoso

Hi Alicia, sorry for the late reply. :)
So, lets see the code. See comments bold

var currentTime = new Date()
var hours = currentTime.getHours()
var hours1 = currentTime.getHours() + 1 //This variable gets current hours + 1
var hours2 = currentTime.getHours() + 2 //This variable gets current hours + 2
var minutes = currentTime.getMinutes()
var weekday=new Array(7);
weekday[0]="Sun";  //Change "Sun" to "Sunday" if you like the output to be Sunday
weekday[1]="Mon"; //...
weekday[2]="Tue";
weekday[3]="Wed";
weekday[4]="Thu";
weekday[5]="Fri";
weekday[6]="Sat";
var day = weekday[currentTime.getDay()];
var date = currentTime.getDate()
var months=new Array(12);
months[0]="1"; //Change "1" to "January" if you like the output to be January
months[1]="2"; //...
months[2]="3";
months[3]="4";
months[4]="5";
months[5]="6";
months[6]="7";
months[7]="8";
months[8]="9";
months[9]="10";
months[10]="11";
months[11]="12";
var month = months[currentTime.getMonth()];
var year = currentTime.getFullYear()
if (minutes < 10)
minutes = "0" + minutes
var timeString=hours + ":" + minutes //this variable gets the current time hours:minutes
var timeString1=hours1 + ":" + minutes //this variable gets the current time hours+1:minutes
var timeString2=hours2 + ":" + minutes //this variable gets the current time hours+2:minutes
var dateString=day + ", " + date + " " + month
var player = GetPlayer();
player.SetVar("SystemDate",dateString);
player.SetVar("SystemTime",timeString); //SystemTime outputs the current time hours:minutes
player.SetVar("systemdateDayOfWeek",day);
player.SetVar("systemdateDay",date);
player.SetVar("systemdateMonth",month);
player.SetVar("SystemTime1",timeString1); //SystemTime1 outputs the current time hours+1:minutes
player.SetVar("SystemTime2",timeString2); //SystemTime2 outputs the current time hours+2:minutes

See file attached :)
Hope this helps you solve the issue.

Regards

Alicia Blitz

Nuno this is amazing, thank you so much! Your explanations here are very helpful. I made one slight change the make it even more like the guide, by changing the minutes to always be 00. I managed to not disrupt any of the code and I actually understand how you did it! This is very exciting.

Many thanks again for your assistance, my boss is going to be blown away! :)

Alicia Blitz

Hi Nuno,

I was working on another project and was trying to modify the script. It's not working at all.

I am trying to modify the current system date the learner is taking the course to simulate a loan screen with the Due Date, Bill Date, and Last Payment Date.

Here's what I have so far:

\\These are setting the months for both Mortgage and Loan

var currentTime = new Date()
var currentMonth = currentTime.getMonth() + 1
var dueMonth = currentTime.getmonths() + 2 //This variable gets current month + 1
var billMonth = currentTime.getmonth() //This variable gets previous month
var LastPmtMonth = currentTime.getmonth() //This variable gets previous month

\\These are setting the dates for both Mortgage and Loan

var day = currentTime.getDate()
var dayLastPmtL ="15" //This is setting the Last Pmt Date day to the 15th
var dayLastPmtM ="1" //This is setting the Last Pmt Date day to the 1st
var dayDueDateL ="15" //This is setting the Due Date day to the 15th
var dayDueDateM ="1" //This is setting the Due Date day to the 1st
var dayBillDateL ="1" //This is setting the Due Date day to the 1st
var dayBillDateM ="16" //This is setting the Due Date day to the 16th

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

\\These are setting the Due Dates for both Mortgage and Loan

var dateStringDueDateM=dueMonth + "/ " + dayDueDateM + "/ " + year
var player = GetPlayer();
player.SetVar("DueDateM",dateStringDueDateM);

var dateStringDueDateL=dueMonth + "/ " + dayDueDateL + "/ " + year
var player = GetPlayer();
player.SetVar("DueDateL",dateStringDueDateL);

\\These are setting the Bill Dates for both Mortgage and Loan

var dateStringBillDateM=billMonth + "/ " + dayBillDateM + "/ " + year
var player = GetPlayer();
player.SetVar("BillDateM",dateStringBillDateM);

var dateStringBillDateL=billMonth + "/ " + dayBillDateL + "/ " + year
var player = GetPlayer();
player.SetVar("BillDateL",dateStringBillDateL);

\\These are setting the Last Pmt Dates for both Mortgage and Loan

var dateStringLastPmtM=LastPmtMonth + "/ " + dayLastPmtM + "/ " + year
var player = GetPlayer();
player.SetVar("LastPmtM",dateStringLastPmtM);

var dateStringLastPmtL=LastPmtMonth + "/ " + dayLastPmtL + "/ " + year
var player = GetPlayer();
player.SetVar("LastPmtL",dateStringLastPmtL);

 

Ashley Terwilliger-Pollard

Hi Alicia,

I'm not sure if folks are still subscribed here, as the post is a bit older - but you could always use the "contact me" button on a ELH users' profile to reach out to them directly! 

As for the variables, if you're using Storyline 3 or Storyline 360, that may be why they're not working as expected. With the changes that were made to our publishing engine, it removed access to some of these system variables that were hidden before (although found/uncovered by users such as yourself). I know a few folks have shared their methods around those changes here in ELH - but it's not something I'm equipped to assist with. I hope you find the help needed!

Ashley Terwilliger-Pollard

Hi Varun,

This discussion is quite a bit older, so you may want to share a bit more detail on what you're looking to set up. It'll be helpful for folks in the community to know the version/update of Storyline you're using, where you're hosting your project, and if you're hoping to use Javascript or another method to pull this information.

Also, you could always use the "contact me" button on a ELH users' profile to reach out to them directly! Best of luck with your project! 

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