Hi VAer-4038,
Based on your code, there are some problems you need to note.
First, you need to declare the "isDateInDatabaseAppointmentTable" method with formal parameters instead of actual parameters.
Then you can't use to operator in For loop.
Finally, you can check day of week with DateTime.DayOfWeek that cheong00 said.
Here is the modified code you can refer to.
public static bool isDateInDatabaseAppointmentTable(DateTime dt)
{
....
}
private void button1_Click(object sender, EventArgs e)
{
var startDate = dateTimePicker1.Value;
var endDate = dateTimePicker2.Value;
for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
{
bool isFound = isDateInDatabaseAppointmentTable(date);
if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
{
MessageBox.Show("It is weekend, you don't work today");
}
else if (isFound == true)
{
MessageBox.Show("You have appointment today, and you don't work today");
}
else
{
}
}
}
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.