从开始日期算起5天的循环次数 [英] How loop to count for 5 days from the start date

查看:89
本文介绍了从开始日期算起5天的循环次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个开始日期,现在我需要做一个循环以从开始日期算起5天.输出应显示接下来5天的日期.请帮忙.

Hi
I have a starting date, now i need to make a loop to count for 5 days from the start date. The output should show the dates for the next 5 days. Please help.

推荐答案

void BindDates()
  {
  for (int i=0; i<5;i++)
  {

      DateTime date=DateTime.Now.AddDays(i);
      Response.Write(date.ToString());

  }
  }


//Set the Start Date
DateTime dtStart = DateTime.Now.Date

//Get the date 5 days greater than start date
DateTime dtEnd = dtStart.AddDays(5)

//Set the looping parameters
DateTime dtLoop = dtStart

//Apply while loop
While (dtLoop < dtEnd)
{
    //Do something with dtLoop here or Print the date value
    Response.Write(dtloop.ToString());

    //Add one dat in the start value
    dtLoop = dtLoop.AddDays(1)
}



希望这会有所帮助.
一切顺利.



Hope this helps.
All the best.


protected void GenrationDate()
       {
           DateTime dtStart = DateTime.Now.Date;

           //Get the date 5 days greater than start date
           DateTime dtEnd = dtStart.AddDays(5);

           //Set the looping parameters
           DateTime dtLoop = dtStart;
           int i = 0;
           for (i = dtStart.Day; i < dtEnd.Day; i++)
           {
               //Printing the Date as short formate
               Response.Write(dtLoop.ToShortDateString() + "<br />");
               //adding one day to date
               dtLoop = dtLoop.AddDays(1);
           }
       }



希望这能起作用....



hope this will work....


这篇关于从开始日期算起5天的循环次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆