Copy link to clipboard
Copied
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!
You can use the following JavaScript to add the leading zeroes to the day and the 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, m
...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
Copy link to clipboard
Copied
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:
http://blog.lilybiri.com/discover-slash-use-captivates-system-variables-part-1
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?
Copy link to clipboard
Copied
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.
Thank you.
Copy link to clipboard
Copied
You will need JavaScript in that case.
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.
Copy link to clipboard
Copied
You can use the following JavaScript to add the leading zeroes to the day and the 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);
You need to place this code into a "Script Window". Use the "Execute Javascript" option either from a button/clickbox press or from within an Advanced Action.
Copy link to clipboard
Copied
Thank you for the coding, it works perfectly!!
Copy link to clipboard
Copied
Thank you so much for you help!!
Copy link to clipboard
Copied
My pleasure!
Copy link to clipboard
Copied
Greetings friend! I hope all is well. I had one more quick question. I've been playing around with javascript and practicing, but I cannot seem to figure out the language to display the year as two digits. Any guidance would be greatly appreciated.
Copy link to clipboard
Copied
Please disregard my last reply. I think I may have found it! Thanks as always!
Copy link to clipboard
Copied
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