Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
dateTimePicker1.Format = DateTimePickerFormat.Custom
dateTimePicker1.CustomFormat = "MMMM yyyy" 
dateTimePicker1.ShowUpDown = True

I have used the above code I need the same format eg. March 2014.It work correctly . But on the 31st of a month it show an exception how can I handle or any other alternatives
for showing this format

Actual purpose of this code is to select month the error occurs on changing the month to another But it only on today (31st october ) or 31st of any month having
Posted
Updated 30-Oct-14 21:23pm
v2
Comments
Thava Rajan 31-Oct-14 3:19am    
what is the actual purpose of this code and why would you use 31st in your date time picker
Moses Geo 31-Oct-14 3:23am    
Actual purpose of this code is to select month the error occurs on changing the month to another But it only on today (31st october ) or 31st of any month having
Thava Rajan 31-Oct-14 5:25am    
why don't you use a two combo boxes since you are using only month and year
could you please post your exact error and the code where the error occurs
because it seems these lines are perfect, it seems you are process the datetimepicker changed event in your code please post that code we will try to solve this issue

1 solution

This code will work but it will not contain the current date if it's bigger than 28, if you don't require to save the date this will work for you.

VB
DateTimePicker1.Format = DateTimePickerFormat.Custom
    DateTimePicker1.CustomFormat = "MMMM yyyy"
    DateTimePicker1.ShowUpDown = True
    Dim getdate As String = My.Computer.Clock.LocalTime.Date.Day
    If getdate > 28 Then
        DateTimePicker1.Value = DateTimePicker1.Value.AddDays(-3)
    End If
 
Share this answer
 

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