How to make a DateTimePicker to display a particular year, month, date & time ?

VKSB 236 Reputation points
2024-03-03T12:49:40.0866667+00:00

Hi All,

I want a DateTimePicker to display a particular year, month, date and time (eg: somebody's Birthday). Is it possible?

What I am trying is; using Textboxes for Year, Month, Date, Hour, Minute & Second to enter the "Birthday & time" and then on Clicking a Button, the DateTimePicker to display the "Birthday & Time" written in those Textboxes.

Could you please let me know how to do this?

Thanks

VKSB

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,733 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 32,056 Reputation points Microsoft Vendor
    2024-03-04T02:57:04.27+00:00

    Hi @VKSB ,

    DateTimePicker.Value.Year is read only.

    Try the following code to change the value of DateTimePicker.

            DateTimePicker1.Value = New Date(CInt(TextBoxYear.Text), CInt(TextBoxMonth.Text), CInt(TextBoxDay.Text))
    
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Castorix31 85,711 Reputation points
    2024-03-03T13:11:32.88+00:00
    0 comments No comments

  2. VKSB 236 Reputation points
    2024-03-03T15:42:27.9133333+00:00

    Hi Castorix31,

    I tried DateTimePicker.Value before asking this question here... I couldn't get it work.

    I tried, DateTimePicker.Value. Year = GivenYear ' TextBox.Text = GivenYear

    And found it didn't work...

    Can you please show me how to use it?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.