views:

48

answers:

3

I stored a date value and retrieve it and the format of the date in the string is yyMMdd. Now when the user loads that from the string i would like to select the DateTimePicker as the user loaded date.

Sample code:

string strDate = strRead.Substring(23, 6);
DateTime dt = DateTime.Parse(strDate);

Can any one give me an idea for the next?

+3  A: 

The most efficient way, I guess:

DateTimePicker p = new DateTimePicker();
DateTime result;
if (DateTime.TryParseExact("101025", "yyMMdd", CultureInfo.CurrentCulture, DateTimeStyles.None, out result))
{
    p.Value = result;
}
abatishchev
+1  A: 

Do you mean

string strDate = strRead.Substring(23, 6);
DateTime dt = DateTime.Parse(strDate);
dateTimePicker.Value = dt;
ohadsc
+1  A: 
dateTimePicker.Value = dt;
dateTimePicker.Focus(); //if by Select to meant to give it the focus
Itay