Comparing two date values

Hi,

I have a situation of extracting one date value from excel and extracting one date value from Portal using get text… Two date values are showing same in message box but when i compare in if as equal or contain it’s not getting true… find the below image and provide solution…




Regards,
Kishore.

Verify if the data types are the same in both.

Both are in string type

also ensure there are no extra spaces

Hi @nanda_kishore

Can you try like below

If DateTime.ParseExact(excelDateValue.Trim(), "dd MMM ddd", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MMM-ddd") = DateTime.ParseExact(portalDateValue.Trim(), "dd MMM ddd", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MMM-ddd")
    ' Matched
Else
    ' Not matched

Regards,

Hi
Do this and then compare
DateVariable1=DateTime.Parse("07 Oct Mon").ToString("dd/MMM")

Replace “07 Oct Mon” with the date variable(String type)

Try this!

@nanda_kishore,

Comparing two dates in string format not a good practice.

You should be parsing the string format dates into datetime datatype and then compare.

hey
it could be related to different type of space chars.
Better approach would be to convert string to date then compare it like below:

Log message = CDate("07 Oct Mon") = CDate("07 Oct Mon")

in above example I used static string, replace it with your desired variables