How to compare two date are equal?

Hi,

I have two variable both are string variable

str1 = “08/20/2024”
str2 = “08/20/2024”

if i use compare option it is going else block like both are not equal.

How to fix this , as per string both are equal but it’s going to else block.

Thanks,
Rama

you are doing a sting comapare and on string is not having the 0 =8 vs 8 so it is not equal

The strings are clearly not equal. One has a zero, the other doesn’t.

If you convert them to DateTime instead of string, you can then check if they are equal.

Also doing .ToString on a string doesn’t do anything, its already a string.

1 Like

Hi @rama_krishna_Rao

Try this

If DateTime.ParseExact(str1, "MM/d/yyyy", System.Globalization.CultureInfo.InvariantCulture) = DateTime.ParseExact(str2, "M/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) Then
    ' Dates are equal
Else
    ' Dates are not equal
End If

Regards,

Visualizations
grafik

Hie @rama_krishna_Rao look your 2 variable value your 2 value are both different thats why your if logic value is not equal


Cheers Happy Automation… :smile:

1 Like

got it thank you @ppr

Thanks a lot Lakshman

1 Like

got it what i did mistake Thanks so much Peter

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.