How to check if a date is less than a year before that another date?

Hello,

I would like to check if a date stored in a variable (for instance 22/04/2015) is less than a year before than another date (for instance 28/09/2015). In this case, the output would be False.

Thanks a lot

Regards

Hi @pal1910,

In If condition
Date1<Date2

suppose the value stored in the string variable
Convert.ToDateTime(Date1)<Convert.ToDateTime(Date2)

Regards,
Arivu

Thank you very much.

What I would like to check if DATE A happens less than one year before than DATE B (not check if DATE A happens before DATE B).

For instance:

02/01/2016 is < than 08/05/2016 but not in one year time. So it would be False.
02/01/2016 is < than 03/01/2017 and also in one year time. So it would be True.

Thanks a lot again.

@arivu96

Hi @pal1910,

Try below code

Date1.AddYears(1)<Date2

Regards,
Arivu

1 Like

Thanks a bunch.

What if one date is in string format and the other one in generic value format?

Thanks!

Hi @pal1910,

For Example

Date1->string format
Date2->Generic value

"13/05/2016"

Convert.ToDateTime(Date1).AddYears(1)<Convert.ToDateTime(Date2.ToString())

Regards,
Arivu