Page 1 of 1

Date Display incorrect

Posted: Fri Oct 07, 2016 7:39 am
by ppbedz
I have some code on an onchange event that will populate a date widget with the current date if the status from a drop-down is changed to "accepted". I have the code working, however the date is displayed as a full date with text and time (see attachment). The date format on the date widget is defined as mm/dd/yy? How can I get my date to display properly?

Thank you,
Patti

Re: Date Display incorrect

Posted: Mon Oct 10, 2016 4:18 pm
by Scott Klement
The formatting on the binding dialog only affects data that is loaded from the bound variable. Or, to put it another way, the binding format is only used when loading data from DDS/RPG, it is not used when loading data from JavaScript.

You'll need to format your date in the JavaScript code.

Re: Date Display incorrect

Posted: Tue Oct 11, 2016 7:18 am
by ppbedz
Scott, Can you help me out with that? I am still a little clumsy with these date objects. Thank you, Patti

Re: Date Display incorrect

Posted: Tue Oct 11, 2016 10:49 am
by Glenn
Patti,

The code below should get you what you need. I've added comments to the code to clarify some things.

Code: Select all

var today = new Date();

// getMonth() returns 0 - 11 (need to increment to match 'normal' dates)
//   Note that it will NOT have leading zeroes
var mm = today.getMonth()+1; 
// Add leading zeroes, if needed
if (mm < 10) {
    mm = '0' + mm;
} 

// getDate() returns the 'day' portion of the date - Note that it will NOT have leading zeroes
var dd = today.getDate();
// Add leading zeroes, if needed
if (dd < 10) {
    dd = '0' + dd;
} 

// getFullYear() returns YYYY - Use substring to get the last 2
var yy = today.getFullYear().toString().substr(2,2); 

var todayDate = mm + '/' + dd + '/' + yy;
alert(todayDate);

Glenn

Re: Date Display incorrect

Posted: Tue Oct 11, 2016 12:44 pm
by ppbedz
Thank you, Glenn!