<Dates Comparison>How can I compare 2 dates which are in form of String?

I am retrieving one date from Excel as ExcelDate and another date as todayDate variable. Both are in string variable. I want to compare them in if condition.

If (excel date is not equal to todaydate)

How can I do it??

for e.g.

exceldate =“12-03-2024”
todayDate =“12-03-2024”

How can I check here

depending on the format we parse the strings into a dateTime and compare both at DateTime base

1 Like

Hi @anjasing

excelDate = DateTime.ParseExact(excelDateStr, “dd-MM-yyyy”, CultureInfo.InvariantCulture)
todayDate = DateTime.ParseExact(todayDateStr, “dd-MM-yyyy”, CultureInfo.InvariantCulture)

If Not excelDate.Equals(todayDate) Then
// Your actions if the dates are not equal
// …
End If

1 Like

Hi @anjasing

Check the below Condition -

- Condition -> DateTime.ParseExact(CurrentRow("Column name").toString, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture).equals(DateTime.ParseExact(todayDate.toString, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture))

If the exceldate is also variable then use below,

- Condition -> DateTime.ParseExact(exceldate.toString, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture).equals(DateTime.ParseExact(todayDate.toString, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture))

Hope it helps!!

1 Like

@lrtetala ,

Can you please confirm if datatype of Excel Date and Today Date variable is System.DateTime?

cz it’s giving me cultureinfo is missing or not decalred
issue

@anjasing

Try this

excelDate = DateTime.ParseExact(excelDateStr, “dd-MM-yyyy”, System.Globalization.CultureInfo.InvariantCulture)
todayDate = DateTime.ParseExact(todayDateStr, “dd-MM-yyyy”, System.Globalization.CultureInfo.InvariantCulture)
1 Like

Hi,

Input:-

Output:-
image

Xaml File:-
date comparision forum.zip (3.0 KB)

If it works for you, please mark it as a solution.

Thanks

1 Like

Okay @anjasing

Then check the below one,

- Condition -> DateTime.ParseExact(ExcelDate.toString, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture).equals(TodayDate)

In the above ExcelDate is System.String datatype variable and TodayDate is in System.DateTime datatype variable

Hope you understand!!

1 Like

@anjasing

DateTime.ParseExact("12-03-2024","dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture)
DateTime.ParseExact("12-03-2024","dd-MM-yyyy",System.Globalization.CultureInfo.InvariantCulture)

image

1 Like

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