I have created a demo form however can not find how to upload it. All the code is below. The 6 fields which date 2 gets data from are (Y1R,Y2R etc). I think I am good with the mandatory fields. The problem seems to be reading the dates and taking the difference.
form1.#subform[0].DATEFIELD2::calculate - (FormCalc, client)
if (M2R.rawValue ne null) then
$.rawValue = (CONCAT(Y1R,Y2R,Y3R,Y4R,"-",M1R,M2R))
else
$.rawValue = ""
endif
form1.#subform[0].DateField1::ready:layout - (FormCalc, client)
$.rawValue = Num2Date(Date(), "MMM-YY")
form1.#subform[0].textfield4::click - (JavaScript, client)
//transform fields to dates
var regularDate1 = new Date(Datefield1.rawValue.replace(/-/g, "/"));
var regularDate2 = new Date(DATEFIELD2.rawValue.replace(/-/g, "/"));
// Get difference between dates in milliseconds
var milliseconds = regularDate1.getTime() - regularDate2.getTime();
// Define number of milliseconds in one day
var nMilliSecondsPerDay = 24 * 60 * 60 * 1000;
// Get difference in days
var days = Math.floor(milliseconds / nMilliSecondsPerDay);
//Display value in Numeric1 field
textfield4.rawValue = days;