First time posting, and I could not seem to locate an answer. Through my search, it seems many of the posts were from before the DD/MM/YYYY format became available. My question is this: Is there a way to format the dat to include the leading zero (for single digit days and months such as 08/02, for the eigth of February. Anytime I see DD/MM/YYYY, I'm expecting it to read 2 digits/2 digits/4 digits. I'm not sure if that's something I got used to in Microsoft Excel. I thought it may be an Adobe convention, but Adobe Acrobat offers a number of formats that include the leading zero. Any guidance would be greatly appreciated!
Not sure to understand completely. Are you talking about system variables? AFAIK they always have been available, but some of them have been added in version 6 which is quite a while ago. Have a look at this table with system variables:
Variables in Captivate are bit weird sometimes. You cannot calculate dates as is possible in Excel. That is the reason you have different formatting options in Captivate. One of them is based on the setup of dates on your system. Can you tell which exact system variable you are using?
Sorry, let me explain. The cpInfoCurrentDate format reads MM/DD/YYYY, so when I place that variable into a project, I'm expecting it to read 02/08/2022 for Febuary 8, 2022. Instead it reads 2/8/2022, and is dropping the zero off of the month and the day. I'm wondering if there is a way to create my own variable that would include the zero, since it does allow us to edit the system variables. I have tried switching the format of my operating system, but it still ignores the zeroes. I hope that explains my query a little better.
You cna combine cpInfoCurrentDate with cpInfoCurrentMonth and cpInfoCurrentYear but you'll need to format the numbers using JS to keep it to 2 numbers both for Date and Month.
// Get the current day of the month
var dd = window.cpAPIInterface.getVariableValue("cpInfoCurrentDate");
// add leading zeroes
var ddStr = ('00' + dd).slice(-2);
//Get the month
var mm = window.cpAPIInterface.getVariableValue("cpInfoCurrentMonth");
// add leading zeroes
var mmStr = ('00' + mm).slice(-2);
//Get the year
var yyyy = window.cpAPIInterface.getVariableValue("cpInfoCurrentYear");
// Concatenate the day, month and year separated by "/"
var fullDateStr = ddStr + "/" + mmStr + "/" + yyyy;
// Assign the Captivate variable formattedDateString
window.cpAPIInterface.setVariableValue("formattedDateString" , fullDateStr);
Thank you for the coding, it works perfectly!!
Thank you so much for you help!!
Please disregard my last reply. I think I may have found it! Thanks as always!
The easiest way is just to use the modulus or "remainder" operator and divide the year by 100 i.e.
yyStr = yyyy % 100;
Or you could use the slice() function to get the last two digits of the year i.e.
yyStr = yyyy.slice(-2);
// Get the last two digits of the year