You could do it in VBA, or as just an expression in a spreadsheet:
=IF(B3>DATEVALUE("1/1/1900"),IF(B3<=A3,1,IF((B3-A3)<7,2,3)),IF(TODAY()<=A3,1,IF((TODAY()-A3)<7,2,3)))
I made a small sample spreadsheet with due date in column A, completion date in column B, and used a third column for this expression. It returns a 1 for the green value, 2 for amber and 3 for red according to your rules.
The actual colors can be stuck into your cells with conditional formatting. You can either make it so it colors the due date with the conditional formatting, or easier, use the third column as the color column. I'll take a screenshot in a bit.
VBA is much nicer to read though, and returns the same numbers and you could probably use it to change the cell formatting as well without using the conditional formats. The below is pretty clunky, but simply done.
Public Function DateColor(due As Date, done As Date, tod As Date) As Integer
If done > "1/1/1900" Then
If done <= due Then
DateColor = 1
Else
If (done - due) < 7 Then
DateColor = 2
Else
DateColor = 3
End If
End If
Else
If tod <= due Then
DateColor = 1
Else
If (due - tod) > 0 Then
DateColor = 1
Else
If (tod - due) < 7 Then
DateColor = 2
Else
DateColor = 3
End If
End If
End If
End If
End Function
Your cell function would just be '=DateColor(DueDateCell, CompletionDateCell, Today())'