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

Recommended Answers

All 6 Replies

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
commented: sir i want current year with next year. 2021-22 finicial year also change year with scroll bar +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

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.

commented: exactly +8

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.