Hi I need help addings dates using for loop in formcalc. I can do manually like this
DateTimeField2.rawValue = Num2Date(Date2num(DateTimeField1.rawValue,"YYYY-MM-DD")+1,"YYYY-MM-DD");
DateTimeField3.rawValue = Num2Date(Date2num(DateTimeField1.rawValue,"YYYY-MM-DD")+2,"YYYY-MM-DD");
DateTimeField4.rawValue = Num2Date(Date2num(DateTimeField1.rawValue,"YYYY-MM-DD")+3,"YYYY-MM-DD");
DateTimeField5.rawValue = Num2Date(Date2num(DateTimeField1.rawValue,"YYYY-MM-DD")+4,"YYYY-MM-DD");
I tryed this for loop:
for i=1 upto 4 do
var temp = "DateTimeField" + (i+1) + ".rawValue"
temp= Num2Date(Date2num(DateTimeField1.rawValue,"YYYY-MM-DD")+ i,"YYYY-MM-DD")
endfor
I know this is wrong, my skill in formcalc is very limited any help is very much appreciate
Henry
Solved! Go to Solution.
Views
Replies
Total Likes
You need to use instance numbers of the fields instead of trying to use different field names.
So, if all your date fields are called DateTimeField1 they will get instance numbers in brackets after them that you can access: DateTimeField1[0], DateTimeField1[1], etc.
Also, you don't need to use rawValue or semicolons with FormCalc.
So below I'm pulling the data from the first instance of DateTimeField1, which defaults to [0] but I put it in anyway to be sure. The loop will start with DateTimeField[1]:
for i=1 upto 4 do
DateTimeField1[i] = Num2Date(Date2Num(DateTimeField1[0], "YYYY-MM-DD") + i, "YYYY-MM-DD")
endfor
Sometimes it's good to use variables to make things easier to read, so I'd probably do this as:
for i=1 upto 4 do
var vDate = Date2Num(DateTimeField1[0], "YYYY-MM-DD")
DateTimeField1[i] = Num2Date(vDate + i, "YYYY-MM-DD")
endfor
Views
Replies
Total Likes
You need to use instance numbers of the fields instead of trying to use different field names.
So, if all your date fields are called DateTimeField1 they will get instance numbers in brackets after them that you can access: DateTimeField1[0], DateTimeField1[1], etc.
Also, you don't need to use rawValue or semicolons with FormCalc.
So below I'm pulling the data from the first instance of DateTimeField1, which defaults to [0] but I put it in anyway to be sure. The loop will start with DateTimeField[1]:
for i=1 upto 4 do
DateTimeField1[i] = Num2Date(Date2Num(DateTimeField1[0], "YYYY-MM-DD") + i, "YYYY-MM-DD")
endfor
Sometimes it's good to use variables to make things easier to read, so I'd probably do this as:
for i=1 upto 4 do
var vDate = Date2Num(DateTimeField1[0], "YYYY-MM-DD")
DateTimeField1[i] = Num2Date(vDate + i, "YYYY-MM-DD")
endfor
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies