c# - Check difference in years -


i trying check whether selected date 2 years (24 months) old in c#. reason getting logic in here, brain overloaded. code. how check if 2 years old?

if (dt.addmonths(-24) < system.datetime) {     return true; } else {     return false; } 

you there. assuming dt date want check more 2 years old, this:

if(dt < system.datetime.today.addmonths(-24)) {   ... } 

running code today (21/05/2013) statement return true when dt 20/05/2011 or earlier. if want include 21/05/2011 use <= instead

note: there addyears method


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -