C# 如何检查单元格值是否在今天起的7天内

C# 如何检查单元格值是否在今天起的7天内,c#,sql,asp.net,date,C#,Sql,Asp.net,Date,我在我的GridView中有一列,它以以下格式显示SQL查询的日期:mm dd yyyy,如果单元格值在今天日期后7天内,我想更改字体颜色 这就是我所拥有的,但它使所有东西的颜色都相同: int inDateOffset = 7; //within 7 days makes it a risk item... if (DateTime.Parse(e.Row.Cells[3].Text).Date > DateTime.Now.AddDays(-inDateOffset).Date) {

我在我的
GridView
中有一列,它以以下格式显示SQL查询的日期:
mm dd yyyy
,如果单元格值在今天日期后7天内,我想更改字体颜色

这就是我所拥有的,但它使所有东西的颜色都相同:

int inDateOffset = 7; //within 7 days makes it a risk item...
if (DateTime.Parse(e.Row.Cells[3].Text).Date > DateTime.Now.AddDays(-inDateOffset).Date)
{
    e.Row.Cells[3].ForeColor = Color.FromName("#DCA704");
    e.Row.Cells[3].ToolTip = "Task is at Risk";
}

如何修改代码,以便从今天起7天内的任何内容都将使用颜色,
\DCA704

更改您的
if
语句以检查结果的
时间跨度,并添加7天:

if ((DateTime.Parse(e.Row.Cells[3].Text).Date 
     - DateTime.Now.AddDays(inDateOffset).Date).TotalDays <= 7)
if((DateTime.Parse(e.Row.Cells[3].Text).Date

-DateTime.Now.AddDays(inDateOffset.Date).TotalDays更改
if
语句以检查结果
TimeSpan
,并添加7天:

if ((DateTime.Parse(e.Row.Cells[3].Text).Date 
     - DateTime.Now.AddDays(inDateOffset).Date).TotalDays <= 7)
if((DateTime.Parse(e.Row.Cells[3].Text).Date

-DateTime.Now.AddDays(inDateOffset.Date).TotalDays更改
if
语句以检查结果
TimeSpan
,并添加7天:

if ((DateTime.Parse(e.Row.Cells[3].Text).Date 
     - DateTime.Now.AddDays(inDateOffset).Date).TotalDays <= 7)
if((DateTime.Parse(e.Row.Cells[3].Text).Date

-DateTime.Now.AddDays(inDateOffset.Date).TotalDays更改
if
语句以检查结果
TimeSpan
,并添加7天:

if ((DateTime.Parse(e.Row.Cells[3].Text).Date 
     - DateTime.Now.AddDays(inDateOffset).Date).TotalDays <= 7)
if((DateTime.Parse(e.Row.Cells[3].Text).Date

-DateTime.Now.AddDays(inDateOffset.Date).TotalDays您的检查是检查日期是否大于7天前。将其翻转,以便检查日期是否小于7天:

if (DateTime.Parse(e.Row.Cells[3].Text).Date < DateTime.Now.AddDays(inDateOffset).Date)
if(DateTime.Parse(e.Row.Cells[3].Text).Date
您的支票正在检查日期是否大于7天前。将其翻过来检查日期是否小于7天后:

if (DateTime.Parse(e.Row.Cells[3].Text).Date < DateTime.Now.AddDays(inDateOffset).Date)
if(DateTime.Parse(e.Row.Cells[3].Text).Date
您的支票正在检查日期是否大于7天前。将其翻过来检查日期是否小于7天后:

if (DateTime.Parse(e.Row.Cells[3].Text).Date < DateTime.Now.AddDays(inDateOffset).Date)
if(DateTime.Parse(e.Row.Cells[3].Text).Date
您的支票正在检查日期是否大于7天前。将其翻过来检查日期是否小于7天后:

if (DateTime.Parse(e.Row.Cells[3].Text).Date < DateTime.Now.AddDays(inDateOffset).Date)
if(DateTime.Parse(e.Row.Cells[3].Text).Date
这将让我知道某物是否在今天起7天内?如何签入SQL?这将让我知道某物是否在今天起7天内?如何签入SQL?这将让我知道某物是否在今天起7天内?如何签入SQL?这将让我知道某物是否在今天起7天内?如何签入SQL?