0
votes

I'm creating a datetimepicker and I want it to have a maxDate until Saturday every week. So for example, today is Sunday 16/10/2016, the maximum for this is 22/10/2016. But if i put maxdate = today + 7 , tuesday maxdate will be monday which I don't want. I want to allow the user to be able to choose in 1 week only. Is this possible ?

Edit: Sorry,I wrote the wrong thing. It is calendar, not datetimepicker.

2

2 Answers

2
votes

DateTime has a DayOfWeek property (that will output the DayOfWeek Monday if it is Monday). You could pass that property into a helper method that determines the number of days until Saturday based on the current day...

1
votes

You could try this:

        DateTime today = DateTime.Today;

        int daysToAdd = 6 - (int)today.DayOfWeek;

        DateTime nextSaturday = today.AddDays(daysToAdd);
        Console.WriteLine(nextSaturday.ToShortDateString());

Ouputs: 10/22/2016