How can i convert the string value to date time value and assign it to DateTimePicker
-
26-09-2019 - |
문제
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?
해결책
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;
}
다른 팁
Do you mean
string strDate = strRead.Substring(23, 6);
DateTime dt = DateTime.Parse(strDate);
dateTimePicker.Value = dt;
dateTimePicker.Value = dt;
dateTimePicker.Focus(); //if by Select to meant to give it the focus
제휴하지 않습니다 StackOverflow