Basic Date Comparison

Hi Team,

I have a basic doubt in date comparison.

Date 1(String) : 03/12/20
Date 2(String) : 02/12/20

For the above case in IF condition getting correct output as Date 1 is greater.

If date 2 changed as 02/12/21 still getting output as Date 1 is greater. How to proceed?
The code should work even if month is changed as a greater month.

1 Like

@Robotics
Yo can not compare string to compare date, use either date difference or compare date to get the correct output.

Hi,

I tried and it worked for me
DT1 = “03/12/2020”
DT2 = “02/12/2021”
IF
DateTime.ParseExact(DT1.ToString,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)>Datetime.ParseExact(DT2.tostring,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)


_test.xaml (5.0 KB)

Yes its working fine, how does it works? DT1 is a string does this code converts the string to date time and doing the comparison ?

Because i am curious to know how to convert a date from
String to DateTime and
DateTime to a String

@Robotics,

Please go through the below link

If your issue is fixed with the above code in previous comment then please mark as resolved.

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