Share via


How to: Retrieve a Date in a DateTimePicker Control

In this example, you select a meeting date in a Windows Forms DateTimePicker control. The selected meeting date and today's date are displayed in message boxes. For more information, see DateTimePicker Control (Windows Forms).

Example

private void button1_Click(object sender, System.EventArgs e)
{
    // Display the selected date and time:
    MessageBox.Show("Your've selected the meeting date: " 
    + dateTimePicker1.Value.Date);

    // Display today's date and time:
    MessageBox.Show("Today is: " + DateTime.Today);
}

Compiling the Code

This example requires:

  • A Windows Form with a DateTimePicker control named dateTimePicker1 and a Button control labeled Select a Meeting Date.

  • Set the event handler of the button to button1_Click.

See Also

Concepts

Designing a User Interface in Visual C#

Other Resources

Date and Time Controls

Visual C# Guided Tour

Button Control (Windows Forms)