I am trying to display only year in datetimepicker in vb.net
Can anybody help me out. please

Write statements in Form1_Load Event.

DateTimePicker1.CustomFormat = "yyyy"
  DateTimePicker1.Format = DateTimePickerFormat.Custom

it works for the final result, but when you click the dropdown button it shows you day and month, I want to pick years only, how can I do that

thanks

Private Sub mainForm_Load(ByVal sender As Object,
            ByVal e As System.EventArgs) Handles Me.Load
        
        ' Set the MinDate and MaxDate.
        dtpYear.MinDate = New DateTime(1753, 1, 1)
        dtpYear.MaxDate = DateTime.Today
        dtpYear.Format = DateTimePickerFormat.Custom
        dtpYear.CustomFormat = "yyyy"
        dtpYear.Value = Today

    End Sub

Open your form designer and select your

date time picker go to properties

in designer window set format to custom

in custom format window set to yyyy no quotes needed

change the numericUpDown property to true.

This will limit the users ability to select

anything other than a year.

Hope this helps

Tim

Try this one. This is so simple.

Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Label1.Text = Me.DateTimePicker1.Value.Year      

    End Sub

it works for the final result, but when you click the dropdown button it shows you day and month, I want to pick years only, how can I do that

thanks

Hi,

If you want only a dropdown with years to select without any days and months, then you doesn't need a datetimepicker but only a combobox completed with years.

Comments
exactly

Hi,

If you want only a dropdown with years to select without any days and months, then you doesn't need a datetimepicker but only a combobox completed with years.

that is great unless you are using a date type. if you are doing this which is just good programing practice then you will run into issues at a latter time.

This article has been dead for over six months. Start a new discussion instead.