FInd out how many days in the future a datetime is
I have this DateTime object:
开发者_运维问答model.Model.Results.FloatingComponent().Schedule.ScheduleRows[0].Payment.FromDate.AdjustedDate
How do I find out how many days into the future that is, if it is in the future?
TimeSpan delta = Foo.AdjustedDate - DateTime.Now;
if(delta.Days > 0)
{
//...
}
Edit:
Based on @Gabe's comment here a version that only looks at the days:
TimeSpan delta = Foo.AdjustedDate.Date - DateTime.Today;
if(delta.Days > 0)
{
//...
}
DateTime mydate = ....
TimeSpan span = mydate.Subtract(DateTime.Now);
// then use span.Days;
int days = (futureDate - DateTime.Today).Days;
精彩评论