Is there a way to customformat DateTimePicker to only allow users to select M-F?
Thank you
Doug
Is there a way to customformat DateTimePicker to only allow users to select M-F?
Thank you
Doug
— and asked for clarification; the short answer is that the DateTimePicker’s format cannot prevent weekend dates. The practical solutions are to (A) prevent/adjust weekend picks on the client side (so users can’t pick them in the UI), and/or (B) always validate server-side and reject weekend values. Below are concise, immediately usable approaches for WinForms and for ASP.NET pages.
WinForms (VB.NET): handle the control events and correct a weekend selection. Use a guard flag to avoid recursion when you set the Value programmatically.
Private _skipFix As Boolean = False
Private Sub DateTimePicker1_CloseUp(sender As Object, e As EventArgs) Handles DateTimePicker1.CloseUp
If _skipFix Then Return
Dim d As Date = DateTimePicker1.Value.Date
Select Case d.DayOfWeek
Case DayOfWeek.Saturday
_skipFix = True
DateTimePicker1.Value = d.AddDays(-1) ' go back to Friday
_skipFix = False
Case DayOfWeek.Sunday
_skipFix = True
DateTimePicker1.Value = d.AddDays(1) ' move to Monday
_skipFix = False
End Select
End Sub ASP.NET / web pages: use a client calendar that supports disabling days (jQuery UI datepicker has beforeShowDay / noWeekends) and also validate on the server.
$('#<%= txtDate.ClientID %>').datepicker({
beforeShowDay: $.datepicker.noWeekends
}); Protected Sub cvDate_ServerValidate(source As Object, args As ServerValidateEventArgs)
Dim d As Date
If Date.TryParse(args.Value, d) Then
args.IsValid = (d.DayOfWeek <> DayOfWeek.Saturday And d.DayOfWeek <> DayOfWeek.Sunday)
Else
args.IsValid = False
End If
End Sub Notes: account for locale-specific weekends if your app is global; always keep server-side validation as the authority. For reference on the .NET DayOfWeek enum and the WinForms DateTimePicker see the Microsoft docs: DateTime.DayOfWeek and DateTimePicker (Windows Forms). For web pickers see the jQuery UI datepicker beforeShowDay option.
Jump to Post— pritesh2010 30what?? i can't understand your question?you want one Datetimepicker which only select Male-Female. just tell me brief.
what?? i can't understand your question?you want one Datetimepicker which only select Male-Female. just tell me brief.
explain ur qestion properly no one will understand ur query
I'm looking to have a datetimepicker custom format that allows a user to only select Monday thru Friday and have the weekends exempt from selection.
Sorry for the confusion.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.