Expand my Community achievements bar.

Adding Number to the Current Date and Displaying a New Date

Avatar

Former Community Member
Good Afternoon,



I have hit a snag in a form that I have been designing for my company. It is essentially a Marketing Workflow chart that takes a job from a drop down list, displays how many days it will take to complete the job, then moves on to the next phase. The drop down list and linear text "1 day, 2 days, ect..." are all working fine. I also have a field named "CurrentDate" which displays the current date, month and year. I have an additional field named DateField, which is where I am stuck. What I am trying to do upon exit of the DropDownList is add the number of days a certain task will take to the CurrentDate and display the new date in the DateField box.



After messing around for a few days, and reading several posts I have come up empty handed. I have not coded in quite some time so this has all been relatively new to me.



I'll post what I have so far below. I've only started the DateField code on the first if statement. Once working, I can move on to the rest:



if (DropDownList1.rawValue == 1){

TextField1.rawValue = "2 Days";

DateField1.formattedValue = Num2Date(Date2Num(DateField1.rawValue, "MM/DD/YYYY") + 2, "DD/MM/YYYY");

}



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 text field comes up blank with this code. I have tried several different variations and methods, and the best I can do is get the DateField1 section to come up with "empty". Again, this is new to me so if I am doing something terribly wrong, please let me know.



Thank you,

Chris
1 Reply

Avatar

Former Community Member
You are mixing languages .....the Num2Date and Date2Num functions are FormCalc functions and the rest of your code is javascript.



Although Num2Date and Date2Num are easier, I would suggest that you stick with javascript as it gives you better looping constructs for what you want to do. There are javascript commands that allow you to create date objects and then get the number of milliseconds that have expired since a set period in time. I belive the command is Date.valueOf(). Now that you have the miliseconds you can add the number of days * 24*60*60*1000 to get milliseconds and then convert the number back to a date. In this way you do not have to deal with leap years, or days in a month etc ....that is all handled for you.



Hope that helps