Date Comparison not working

I have the code below in a agent with the below mentioned values in the varables.The 1st if statement gives the correct result(“True”).But the second statement does not work properly.I used Format,CDat,CVDate functions.They convert my variable value in to 31/12/1999 or 12:00:00.why is this happening.And why when 1 works fine does the other not.

c_Date = 2/28/05

sub16_4 = 20040909

sub16_5 = 20050909

If C_Date > sub16_4 Then

Msgbox(“true 4”)

End If

If C_Date <= sub16_5 Then

Msgbox(“true 5”)

End If

Any help will be greatly apriciated.

Thanks in advance

Malik

Subject: Date Comparison not working

You’re comparing (variant) numbers – not dates. Using more informative messages readily reveals the problem with your code, but you should use the debugger to check variable values instead of message boxes.

Dim c_Date As Variant

Dim sub16_4 As Variant

Dim sub16_5 As Variant

c_Date = 2/28/05 ’ this evaluates to 2 divided by 28 divided by 5, which is 0.0142857142857143

sub16_4 = 20040909

sub16_5 = 20050909

If c_Date > sub16_4 Then

Msgbox "True 4: " & c_Date & " IS greater than " & sub16_4, , "Results . . ."

Else

Msgbox "False 4: " & c_Date & " is NOT greater than " & sub16_4, , "Results . . ."

End If

If c_Date <= sub16_5 Then

Msgbox "True 5: " & c_Date & " IS less than or equal to " & sub16_5, , "Results . . ."

Else

Msgbox "False 5: " & c_Date & " is NOT less than or equal to " & sub16_5, , "Results . . ."

End If