C Sharp添加天数问题

C Sharp添加天数问题

问题描述:

在下面的代码中,我使用AddDays运算符来添加天数。但我的要求是从 dsStartDate 中扣除天数。请有人帮帮我吧!

if(ddlMaintenPlan.SelectedItem.Text ==Weekly)

{

DateTime dtLastday = Convert.ToDateTime(dtpMaintenceEnd.Text.Trim());





DRLocal = DTLocal.NewRow();

DateTime dtS = Convert.ToDateTime(dtpMaintenceStart.Text.Trim());

DTLocal.Rows.Add(dtS);





while(dsStartDate< = dtLastday)

{

dsStartDate = dsStartDate.AddDays(7);

DRLocal = DTLocal.NewRow();

DTLocal.Rows.Add(dsStartDate);









DTLocal.Rows.Add(dsStartDate);

//}

}







}

In the following code I used AddDays operator to add days. But My requirement is to deduct days from dsStartDate. Can anyone help me, please!!!
if (ddlMaintenPlan.SelectedItem.Text == "Weekly")
{
DateTime dtLastday = Convert.ToDateTime(dtpMaintenceEnd.Text.Trim());


DRLocal = DTLocal.NewRow();
DateTime dtS = Convert.ToDateTime(dtpMaintenceStart.Text.Trim());
DTLocal.Rows.Add(dtS);


while (dsStartDate <= dtLastday)
{
dsStartDate = dsStartDate.AddDays(7);
DRLocal = DTLocal.NewRow();
DTLocal.Rows.Add(dsStartDate);




DTLocal.Rows.Add(dsStartDate);
//}
}



}

尝试:

Try:
dsStartDate = dsStartDate.AddDays(-7);