Calculate date

Aug 13, 2020

Hi,

I would like to know if there's a script where you can get an End date when a day added into the First date. Example

First date : 05/20/2020

Days : 30 

End date : 06/19/2020 (this is what i want to achieve)

1 Reply
Joseph Francis

Yes, but you will need to use Javascript to do it. Starting with this as a framework, you can use this:

var strDate = new Date();

strDate.setDate(strDate.getDate() + 30);

var mm = strDate.getMonth() +1;
var dd = strDate.getDate();
var yyyy = strDate.getFullYear();
var strDate = mm + "/" + dd + "/" + yyyy;

var player = GetPlayer();
player.SetVar("endDate", strDate);

Note, Javascript months are 0-11, which is why you have to add 1 to the getMonth() method.

The getDate() method returns the current date. "+30" (on line 2) adds 30 days to that retrieved date.

The result (strDate, which you would then populate into the Storyline variable "endDate" in your course) would be displayed as "MM/DD/YYYY."

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