Forum Discussion
compare 2 dates in storyline
thank you for reply
not very familiral with javascript so can you help?
I could, but you first have to clarify your needs better. What dates are compared ? How do users enter those ? How is it checked that the dates entered indeed are proper dates ?
If date users entered is todays date = always correct.... because todays date is today :-)
- DafniDean-a4e6a2 days agoCommunity Member
thank you again
Basically we are trying to make sure users complete a form correctly so there is a text entry were staff are asked to enter a date (format DD/MM/YYYY) . On their instructions they are asked to enter the date they complete the course so thats why we are using todays date
hope this makes sense
- MathNotermans-92 days agoCommunity Member
Actually not completely :-)
So they enter a data and when is the check done in Storyline ?
If the check is done the same day... then a === check will do...
if( today === dateEntered ) {
console.log("Hurray, you did well !!!");
}else{
console.log("Do check your date entry, as this seems wrong");
}
Where today will be the currentdate...
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
console.log("today is: "+today);
And ofcourse dateEntered will be the variable you use.
Probably wise to convert both to Strings before the check..
So something like this will work...var player = GetPlayer(); var today = new Date(); var dd = String(today.getDate()).padStart(2, '0'); var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! var yyyy = today.getFullYear(); today = mm + '/' + dd + '/' + yyyy; console.log("today is: "+today); var dateEntered = player.GetVar("variable in Storyline for the date the user entered"); if( today.toString() === dateEntered.toString() ) { alert("Hurray, you did well !!!"); }else{ alert("Do check your date entry, as this seems wrong"); }