Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am having a date time picker on my form. As date time picker displays current date and if that date is Saturday or Sunday i would like to select the next Monday as selected date and also i would like to make all Saturdays and Sundays as non-selectable one.

Any idea please
Posted

1 solution

You can do it by using given code.

C#
if (dateTimePicker1.Text.Contains("Saturday"))
           {
               dateTimePicker1.Text = dateTimePicker1.Value.AddDays(2).ToString();
           }
           else if(dateTimePicker1.Text.Contains("Sunday"))
           {
               dateTimePicker1.Text = dateTimePicker1.Value.AddDays(1).ToString();
           }


and there is no direct option to disable or hide specific date.
whatever, move Google for More Help.
:)
 
Share this answer
 
v2
Comments
demouser743 27-Nov-10 4:07am    
But how can i stop him from selecting that dates which are Saturday or Sunday
RaviRanjanKr 27-Nov-10 4:13am    
simple by Passing Message to user
if (dateTimePicker1.Text.Contains("Saturday") || dateTimePicker1.Text.Contains("Sunday"))
{
// Pass Message Here
}
demouser743 27-Nov-10 4:23am    
So what you are saying is we can not make those as non selectable as we did in web forms
dmageiras 27-Nov-10 4:26am    
Nice, but it would be better if you used DayOfWeek constants, something like this:
System.DayOfWeek i = dateTimePicker1.Value.DayOfWeek;
if((i == System.DayOfWeek.Sunday) || (i == System.DayOfWeek.Saturday)) { ... }
RaviRanjanKr 27-Nov-10 4:30am    
I am not getting about Web Form because question tag is about WinForm. whatever,
Yes you can use it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900