Want to find difference between 2 date

Hi…I want to check the input date should not be more than 2 years… means input date should b less than 27/08/2021… if input date is more than 27/08/2021, it should throw an error… dono how to handle…pls help me out

1 Like

Fine
Let’s take like in_datestr = “22/08/2019”
Then use a if condition like this

DateTime.parseexact(in_datestr,”dd/MM/yyyy”,System.globalization.cultureinfo.invariantculture) > Now.AddYears(2)

If this is true it means it is greater than two years from today

Cheers @Saran

1 Like