So I wrote this piece of code (it’s actually part of a something bigger but this part gives me the problems) and I’m new to VBA so I can’t figure out why this always returns 0 as the formula result.
Function test(begindatum As Date, einddatum As Date)
Dim Days1
If begindatum < 1 / 9 / 1996 And begindatum > 31 / 7 / 1986 Then
If einddatum > 31 / 8 / 1996 Then
Days1 = DateDiff("d", 1 / 9 / 1996, begindatum)
Else: Days1 = DateDiff("d", einddatum, begindatum)
End If
End If
test = Days1
End Function
I tested with various dates btw, all of them returned the output 0.
Would appreciate it if someone could point out where I went wrong.
Kindly regards,
Daquicker
Your dates;
are mathematical expressions – 1 divided-by 9 divided by 1996 – which will be zero when coerced to an integer type.
for a literal date use: