i want to compare two columns in one data table which contains dates.
e.g.
Column1 Column2
02.01.22 03.05.22
12.02.20 05.03.22
I tried it in a for each loop with currentrow.item(“column1”).toString <> currentrow.item(“column2”).toString
It doesnt work properly. The code shows me also equal date values.
Hi @Schlosser_Tobias you can try this, first try to parse the date using Datetime.ParseExact(currentrow.item(“column1”).toString,“dd.MM.yy”,System.Globalization.CultureInfo.InvariantCulture) <> Datetime.ParseExact(currentrow.item(“column2”).toString,“dd.MM.yy”,System.Globalization.CultureInfo.InvariantCulture) and place this in IF condition
As you are comparing the date values to be Equal or Not, we could go with the String Comparison and Check if they are Equal provided they are in the same formats.
Hence, Inspect the date value from the row item at first. There might be a possibility that the Time also gets displayed or present in the value separating the date value with a space.
Next, For Comparison of only date values, we can use the below Expression :
Do note that above String comparison on date values can be performed only when the operation is to Check Equal or Not Equal, else we would require to Convert the String date value to DateTime and then Compare
Datetime.ParseExact(stringVar,format of stringVar,System.Globalization.CultureInfo.InvariantCulture)
eg. Datetime.ParseExact(“02/15/2022”,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
i have figured out that i have in column1 the values from type date and in column2 type String. If i convert the date type into string it seems to be the best way. But there is another problem, that i have in some rows from column1 no value and i got on this point an exception.