You can use the [[ operator to subset the data frame instead of $. That will allow you to construct strings of the column names and use those in the sub setting.
for ( i in 1:6){
OutVar <- paste0("d", i, "d", i + 1)
LeftVar <- paste0("final.date_testD", i)
RightVar <- paste0("final.date_testD", i + 1)
commun[[OutVar]] <- round(time_length(interval(commun[[LeftVar]], commun[[RightVar]]),"years"),2)
#print(paste(OutVar, LeftVar, RightVar))
}
I included a print statement as a comment. If you remove the comment mark, you can see that the column names are correct, or not.
Edit:
The original code had one of the variable names wrong.
for ( i in 1:6){
OutVar <- paste0("diffd", i, "d", i + 1)
LeftVar <- paste0("final.date_testD", i)
RightVar <- paste0("final.date_testD", i + 1)
commun[[OutVar]] <- round(time_length(interval(commun[[LeftVar]], commun[[RightVar]]),"years"),2)
#print(paste(OutVar, LeftVar, RightVar))
}