c# - Getting a negative number from DateTime.Subtract -


this question has answer here:

my sysadmin has failed expire passwords in ad , password expiry warning system starting count instead of showing negative days. i'm expecting remainingdays negative number test account ( 5 days pseudo-expired) following code, hoping can show me why i'm losing negative. i've read on msdn, datetime.subtract can return negative values.

datetime today = datetime.now; foreach (user user in users) {   datetime expirydate = user.pwdlastreset.adddays(180);   //pwd expires every 180 days   int remainingdays = int32.parse(expirydate.subtract(today).tostring("%d"));   //snipped code send warnings @ different days remaining. } 

datetime.tostring("%d") return day of month represented. example, following code:

datetime prev = datetime.now.subtract(timespan.fromdays(10)); console.writeline(prev.tostring("%d")); 

prints out "15" (as in, "july 15, 2016"), not 10 or -10.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -