How do I get only the Date from a DateTime Picker in C#?
no man its gives 12:00 AM accompanied...
srinivas
2009-07-16 15:04:21
+4
A:
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");
tardomatic
2009-07-16 14:58:32
+1
A:
You mean how to get date without the time component? Use DateTimePicker.Value.Date But you need to format the output to your needs.
Vivek
2009-07-16 15:00:54
A:
@Shoban It looks like the question is tagged c# so here is the appropriate snipped http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.value.aspx
public MyClass()
{
// Create a new DateTimePicker
DateTimePicker dateTimePicker1 = new DateTimePicker();
Controls.AddRange(new Control[] {dateTimePicker1});
MessageBox.Show(dateTimePicker1.Value.ToString());
dateTimePicker1.Value = DateTime.Now.AddDays(1);
MessageBox.Show(dateTimePicker1.Value.ToString());
}
jon37
2009-07-16 15:04:05