Expand my Community achievements bar.

Calculating and Displaying Dates in Javascript

Avatar

Former Community Member
Hello,



I'm working on a flowchart form for my work, and am having issues getting a date to a) add correctly and b) display only certain portions of the date.



I have four fields:

CurrentDate - Displays the Current Date in MM/DD/YYYY format

DropDownList1 - Contains a list of projects end users can choose from

TextField1 - Displays text that tells the end user how many days the proejct will take

DateField1 - Should add the CurrentDate + the Number of days the project will take and return a new date in the same MM/DD/YYYY format



*Disclaimer* - I am not very experienced with scripting, and chose to go with JavaScript as I do have some previous past experience.



Here is what I have for my code right now:



if (DropDownList1.rawValue == 1){

TextField1.rawValue = "2 Days";

var AddDate = (Date.valueOf(CurrentDate) + (2*1000*60*60*24));

DateField1.formattedValue = Date(AddDate);



}



else if (DropDownList1.rawValue == 2){

TextField1.rawValue = "1 Day";

}



else if (DropDownList1.rawValue == 3){

TextField1.rawValue = "2 Days";

}



else if (DropDownList1.rawValue == 4){

TextField1.rawValue = "2 Days";

}



else if (DropDownList1.rawValue == 5){

TextField1.rawValue = "4 Days";

}



else if (DropDownList1.rawValue == 6){

TextField1.rawValue = "5 Days";

}



else if (DropDownList1.rawValue == 7){

TextField1.rawValue = "4 Day";

}



The end result is that the TextField1 displays the correct day, but the DateField1 displays a long string of the exact time and date of... well, the time - so no adding takes place. What I need is for the date to be displayed as MM/DD/YYYY. What am I doing wrong? I've only added the calculation to the first "if" statement, and will continue on to the rest once it is functioning.
21 Replies

Avatar

Level 3

I have a date field validated to display as MMYY. I want my date field to start at 0114. I need the end date to end at 1214. Is this possible? How would this be coded in java script or formcalc?