I would like to add the date variable to a completion certificate. I have the JavaScript coding to capture the current system date, however, I want to ensure that the date locks and doesn't change each time the SCORM is accessed. Also, I want to display the date as full month description, day and year (i.e. January 1, 2015). Does anyone have the JavaScript coding for full month, day and year, with the lock down feature?
This is the code I use. Just use SetVar on the date variable and it should display in the formatting you want.
var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var today = new Date(); var dd = today.getDate(); var mm = today.getMonth(); var yyyy = today.getFullYear(); if(dd<10) { dd='0'+dd } var date= m_names[mm]+' '+dd+', '+yyyy;
var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() var dateString=month + "/" + day + "/" + year var player = GetPlayer(); player.SetVar("SystemDate",dateString);
with -
var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var today = new Date(); var dd = today.getDate(); var mm = today.getMonth(); var yyyy = today.getFullYear(); if(dd<10) { dd='0'+dd } var date= m_names[mm]+' '+dd+', '+yyyy; var player = GetPlayer(); player.SetVar("SystemDate",date);
And it should work great. Make sure to replace the "SystemDate" with the name of whatever variable you're using to story the date value in storyline.
Hi Jackson, not sure if you have the answer to this but is there a way to lock in the date. When I accessed my test SCORM file today, the date changed from yesterday's date to today's date. Is there a way to capture the date of completion to lock the date and not cause it to change when learners go back in.
I am looking for some JS to convert a date to the Day of the Year (Julian). I want to use the DOY and year to time stamp when a user first enters a course. When they reenter I want to compare the dates.
My end goal is to make a user restart a course if they haven't finished within a certain number of days of starting.
I though the Julian Day and current year would be easier to control and compare.
Any chance you would be willing to show me how to get this code to show up in this SystemDate format: Mon 12/7/2015 9:45 AM ? I am mimicking Outlook and while I can get the SystemDate to appear with your code (thank you!) I might as well ask for the moon! :)
Hi Bridget! Jackson's response was quite a few months back and I'm not sure if he's still subscribed here. You are welcome to contact him via the 'Contact Me' option on his user profile if you do not hear back from him soon.
var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1; var wd = weekday[today.getDay()]; var yyyy = today.getFullYear(); var time = formatAMPM(today); var date= wd+' '+mm+'/'+dd+'/'+yyyy+' ' +time;
var player = GetPlayer(); player.SetVar("date",date);
Basically yes, the final variable 'date' in the script is being pushed to the storyline variable.
If its not working I would double check the name of your storyline variable. Mine was also named date, but perhaps you named yours 'systemDate' or something like that?
I would also double check that your browser is enabled to view javascript just in case thats the problem.
@All - I thought this was so cool (THANKS JACKSON!!!), but when I tried it, it didn't work the first time. I went back in and discovered that variables are case sensitive.
I initially added a variable called "Date" and then executed Jackson's script exactly and it didn't work. Once I updated the variable to "date" it worked like a dream!
Sorry, I am just starting our with Storyline 2. I want to populate certificate of completion with the current date. Are there any screenshots out there shat show where the javascript code needs to be inserted?
33 Replies
This is the code I use. Just use SetVar on the date variable and it should display in the formatting you want.
Thanks Jackson. Would I use this SetVar code in addition to the current date code? Or just this SetVar code? The JS code I have for current date is:
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var dateString=month + "/" + day + "/" + year
var player = GetPlayer();
player.SetVar("SystemDate",dateString);
Thanks for sharing Jackson :)
Replace your current code -
with -
And it should work great. Make sure to replace the "SystemDate" with the name of whatever variable you're using to story the date value in storyline.
Thanks Jackson! The code you provided worked. Thanks again for providing the info.
Hi Jackson, not sure if you have the answer to this but is there a way to lock in the date. When I accessed my test SCORM file today, the date changed from yesterday's date to today's date. Is there a way to capture the date of completion to lock the date and not cause it to change when learners go back in.
have the trigger that runs the JS only trigger if the Date value is empty maybe? That way it only runs once
.
I am looking for some JS to convert a date to the Day of the Year (Julian). I want to use the DOY and year to time stamp when a user first enters a course. When they reenter I want to compare the dates.
My end goal is to make a user restart a course if they haven't finished within a certain number of days of starting.
I though the Julian Day and current year would be easier to control and compare.
To get the Julian day, try this:
"
Date.prototype.getDOY = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((this - onejan) / 86400000);
}
var today = new Date();
var daynum = today.getDOY();
var player = GetPlayer();
player.SetVar("TodaysJulianNumber",daynum);
"
In this example, I used a Storyline variable 'TodaysJulianNumber' to store the Julian day number.
Thanks Michael! That's similar to what I found online, but yours actually works!
Works perfect!
Thanks Jackson for sharing the details on how to run the script.
Cheers
Sandy
Glad that Jackson has been able to assist you with all of this Sandy :)
This post was removed by a moderator
Jackson -
Any chance you would be willing to show me how to get this code to show up in this SystemDate format: Mon 12/7/2015 9:45 AM ? I am mimicking Outlook and while I can get the SystemDate to appear with your code (thank you!) I might as well ask for the moon! :)
Hi Bridget! Jackson's response was quite a few months back and I'm not sure if he's still subscribed here. You are welcome to contact him via the 'Contact Me' option on his user profile if you do not hear back from him soon.
Here ya go buddy:
You are awesome, Jackson! Worked like a charm!! Thanks so much!
no problem! Glad I could help :)
That's pretty cool Jackson.
Are you just displaying the variable "date"? I copied the JavaScript to give it a try and it is not working for me.
Hi Alicia,
Basically yes, the final variable 'date' in the script is being pushed to the storyline variable.
If its not working I would double check the name of your storyline variable. Mine was also named date, but perhaps you named yours 'systemDate' or something like that?
I would also double check that your browser is enabled to view javascript just in case thats the problem.
Alicia -
I had %SystemDate% as my variable. So when I copied Jackson's code I just went in and changed 'date' to 'SystemDate'. Worked perfectly.
@All - I thought this was so cool (THANKS JACKSON!!!), but when I tried it, it didn't work the first time. I went back in and discovered that variables are case sensitive.
I initially added a variable called "Date" and then executed Jackson's script exactly and it didn't work. Once I updated the variable to "date" it worked like a dream!
Thanks again!
Sorry, I am just starting our with Storyline 2. I want to populate certificate of completion with the current date. Are there any screenshots out there shat show where the javascript code needs to be inserted?
Hi Gene!
Check out this article on JavaScript best practices and examples. There is a thread that may be helpful here as well.
We defer to the community on this expertise though :)
For anyone following along, Michael was able to assist Gene here.
This discussion is closed. You can start a new discussion or contact Articulate Support.