How can I modify Brian's javascript to get the correct date?

Dec 19, 2013

Could anyone (or Brian) please tell me how to modify Brian's javascript so that I can get the current date minus x number of days.    The script needs to recognize that the result has to be an actual date; not a negative number.  So, if it's only 12/3/2013, subtracting 5 days shows 12/28/2013, NOT 12/-2/2013.

Here's the script which works to get today's date:

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);

7 Replies
Curt Zilbersher

Close, but not exactly.  Please see my screen grabs.  The first shows the screen in Storyline.  The text variable (pointed to by the arrow), when run in the browser, will reveal today's date without the slashes (e.g., 12192013).  I need it show today's date MINUS 6 days (e.g., 12132013).  Thanks for your help!!

Curt Zilbersher

Mike, this is very close!   However, I simply want the text field to show today's date minus 6 days without the user having to click a radio button.  It should automatically appear when the user arrives at this screen.  That date should just simply appear like this:  "The date is 12142013"  (for when today's date is 12/20/2013).   I tried tweaking the code but I wasn't able to get the text field to display. Any final help? (I promise, I won't bug you again!)  

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