C # How to determine if a date is within 180 days

How to determine if a date is within 180 days?

I played with DateTime.Compare below and used date1 +180 days (date1 - August 28, 2009 13:12)

DateTime.Compare(**date1**.AddDays(180), now) 

Is it correct?

thanks

Jamie

+4
source share
2 answers
 DateTime.Now.Subtract(dt1).Days <= 180 
+9
source
 if (Math.Abs(DateTime.Now.Subtract(date1).Days) <= 180) { ... } 

This will let you know if date1 is within 180 days IN THIS DIRECTION right now - in the past or in the future. If you only need in the past, go to Developer Art .

+4
source

Source: https://habr.com/ru/post/1302145/


All Articles