在我的程序中,有两个datetimepicker。我需要获取选定日期之间的日期,并将它们存储到列表或数组中。所有这些都将在第二个datetimepicker值更改事件中完成

private void dateTimePickertodate_ValueChanged(object sender, EventArgs e)
{
    if (dateTimePickertodate.Value <=dateTimePickerfromdate.Value)
    {
        MessageBox.Show("Choose Correct date");
        textBoxnumofdays.Clear();
    }
    else
    {
        cleave = new LeaveApplication(constr);
        TimeSpan span = dateTimePickertodate.Value - dateTimePickerfromdate.Value;

        if (Mode == 1)
        {
            textBoxnumofdays.Text = Convert.ToString(span.Days + 2);
        }
        else
        {
            textBoxnumofdays.Text = Convert.ToString(span.Days + 1);
        }
    }
}

最佳答案

您可以在这些线路上尝试一些方法

DateTime dtFrom = new DateTime(2011, 02, 5);
DateTime dtTo = new DateTime(2011, 02, 9);
List<DayOfWeek> days = new List<DayOfWeek>();
while (dtTo != dtFrom)
{
   dtFrom = dtFrom.AddDays(1);
   days.Add(dtFrom.DayOfWeek);
}


天将有您的工作日列表(如果您打算这样做)

09-06 13:39