How to get only the date value from a Windows Forms DateTimePicker control?

srinivas picture srinivas · Jul 16, 2009 · Viewed 330.1k times · Source

I'm building an application with C# code.
How do I get only the date value from a DateTimePicker control?

Answer

tardomatic picture tardomatic · Jul 16, 2009

I'm assuming you mean a datetime picker in a winforms application.

in your code, you can do the following:

string theDate = dateTimePicker1.Value.ToShortDateString();

or, if you'd like to specify the format of the date:

string theDate = dateTimePicker1.Value.ToString("yyyy-MM-dd");