need assistance using Javascript to display altered day/date in MM/DD/YYYY Format
Hello everyone,
I’m trying to get Captivate 2019 to display the day and date but with an increment/decrement to the day/date.
I found a previous post where a user was able to successfully do this; however, it formats the date in DD/MM/YYYY format. I have never used JavaScript before and cannot figure out how to change the formatting to be MM/DD/YYYY.
Below is the extra code in standard.js followed by the simple script used to manipulate the date. The result will be outputted as a variable so I can display it in a text caption.
Can anyone help with the formatting to have it shown in a US date format?
Thanks!
…………………………………………………………………………………………………………………………………..
function date_math(increment,return_var){
var now = new Date();
now.setDate(now.getDate() + parseFloat(increment)); var nowStr = (now.getDate() < 10 ? “0” + now.getDate().toString() : now.getDate().toString()) + “/” + (now.getMonth()+1 < 10 ? “0” + (now.getMonth()+ 1).toString() : (now.getMonth()+1).toString()) + “/” + now.getFullYear().toString(); document.Captivate.cpEISetValue(return_var,nowStr);
}
date_math(-11,”DateMinus11Variable”);
date_math(-8,”DateMinus8Variable”);
date_math(-3,”DateMinus3Variable”);
date_math(-2,”DateMinus2Variable”);
date_math(-1,”DateMinus1Variable”);
date_math(0,”d0″);
date_math(28,”d_p28″);
date_math(15,”d_p15″);
This may work for you.
function date_math(increment,return_var){
var now = new Date();
now.setDate(now.getDate() + parseFloat(increment));
var nowStr = (now.getMonth()+1 < 10 ? “0” + (now.getMonth()+1).toString() :
(now.getMonth()+1).toString()) + “/” + (now.getDate() < 10 ? “0” + (now.getDate() ).toString() : (now.getDate() ).toString()) + “/” + now.getFullYear().toString(); document.Captivate.cpEISetValue(return_var,nowStr);
}
date_math(-11,”DateMinus11Variable”);
date_math(-8,”DateMinus8Variable”);
date_math(-3,”DateMinus3Variable”);
date_math(-2,”DateMinus2Variable”);
date_math(-1,”DateMinus1Variable”);
date_math(0,”d0″);
date_math(28,”d_p28″);
date_math(15,”d_p15″);
Forgive me for perhaps going in a slightly different direction here but perhaps it may help.
In this example I simply made my SmartShape with text as show in the picture provided.
I made three Captivate variables mm, dd, and yyyy to display each thing separately.
I also made four buttons to increment and decrement the month and day.
There is a little JavaScript placed in the onEnter action of the slide – that is shown in the picture.
Then there is a little JavaScript on each button that just increments or decrements the value and lets it wrap around from 31 to 1 or 1 to 31 depending on the direction you are going. I did not add any logic to check the month and limit proper day choices.
//code to increment month
++mm;if (mm==13) {
mm=1;
}//code to decrement month
–mm;if (mm==0) {
mm=12;
}//code to increment day
++dd;if (dd==32) {
dd=1;
}//code to decrement day
–dd;if (dd==0) {
dd=31;
}
You must be logged in to post a comment.