Convert time and comparaison

Hello,

I had to convert get Date Now + Months 2 in a variable (for exemple 23/12/2018), compare it to a string from excel sheet:

for ex:
31/12/2018
31/08/2018
30/12/2018
22/07/2018

i’m using DateTime.ParseExact(DateTime.Now.AddMonths(+2).ToString(“dd/MM/yyyy”), “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture), but it gives: 12/23/2018 00:00:00

Use Now.tostring(“dd/MM/yyyy”)

You can also compare both in datetime format itself by below condition.

Convert.todatetime(“31/12/2018”)=Today :slightly_smiling_face:

but i need the M+2 date!!!

Now.addmonths(2).tostring(“dd/MM/yyyy”)

image

yes but i need to compare it to values coming from Excel (string)
i had to convert the two in to datetime type

Than your condition should be

If Convert.todatetime(row[Date].tostring)=Today.addmonths(2) (Inside For Each Row)

OK i think that there is a misunderstood:

I had to convert get Date Now + Months 2 in a variable (for exemple 23/12/2018)

read the following Excel Sheet:
|image

Check for the dates which are > (Date Now + Months 2) , that all the values in Column C are equals or the difference between them are < 5 %