Comparing DateTimes in C# -
private void validateeffectivedate() { bool icadvanced = sessionmanager.displayuser.isinrole(permissions.hasicadvanced); if (!icadvanced && model.effectivedate < datetime.now) { this.checkandaddvalidation("effectivedate", "you not have advanced permission, " + "are unable value historical indications."); } }
if not icadvanced, should not able have date in past, 1 day before today or earlier. however, can have today or in future.
why code not reflecting correctly?
well, you're going now, rather today 1 thing. if "now" 5pm, effectivedate midnight today, that's going add validation error.
so might want:
if (!icadvanced && model.effectivedate < datetime.today)
however, need work out how model.effectivedate
represented. datetime
unfortunate of handling of time zones, value can utc, local or unspecified. i'm not clear on how affects comparisons (if compare "local midnight" "utc midnight" in time zone of utc+5, should result be)? think treats both of them being local, compare "local midnight" , "utc midnight" being same. worth thinking though.
Comments
Post a Comment