开发者

FInd out how many days in the future a datetime is

开发者 https://www.devze.com 2023-02-14 12:07 出处:网络
I have this DateTime object: 开发者_运维问答 model.Model.Results.FloatingComponent().Schedule.ScheduleRows[0].Payment.FromDate.AdjustedDate

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消