Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Date Format Captivate Variables

New Here ,
Feb 08, 2022 Feb 08, 2022

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!

894
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Participant , Feb 09, 2022 Feb 09, 2022

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

...
Translate
Participant , Mar 17, 2022 Mar 17, 2022

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

 

 

Translate
LEGEND ,
Feb 08, 2022 Feb 08, 2022

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?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 08, 2022 Feb 08, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 08, 2022 Feb 08, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 09, 2022 Feb 09, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 09, 2022 Feb 09, 2022

Thank you for the coding, it works perfectly!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 09, 2022 Feb 09, 2022

Thank you so much for you help!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 09, 2022 Feb 09, 2022

My pleasure!  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2022 Mar 17, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2022 Mar 17, 2022

Please disregard my last reply.  I think I may have found it!  Thanks as always!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 17, 2022 Mar 17, 2022
LATEST

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

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources