6
Contributors
6
Replies
22
Views
8 Years
Discussion Span
Last Post by tim.newport
0

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
0

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

0
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

0

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
1

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.

Votes + Comments
exactly
0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.