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

Date Format Captivate Variables

New Here ,
Feb 08, 2022 Feb 08, 2022

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!

Views

168

Likes

Translate

Translate

Report

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

Explorer , 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

...

Likes

Translate

Translate
Explorer , 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

 

 

Likes

Translate

Translate
Community Expert ,
Feb 08, 2022 Feb 08, 2022

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?

 

Likes

Translate

Translate

Report

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

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.

Likes

Translate

Translate

Report

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
Community Expert ,
Feb 08, 2022 Feb 08, 2022

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.

Likes

Translate

Translate

Report

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
Explorer ,
Feb 09, 2022 Feb 09, 2022

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you for the coding, it works perfectly!!

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you so much for you help!!

Likes

Translate

Translate

Report

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
Explorer ,
Feb 09, 2022 Feb 09, 2022

Copy link to clipboard

Copied

My pleasure!  

Likes

Translate

Translate

Report

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

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Explorer ,
Mar 17, 2022 Mar 17, 2022

Copy link to clipboard

Copied

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

 

 

Likes

Translate

Translate

Report

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