I have a textbox (txtMyDate) in which I enter a date in the format "yyyy-MM-dd" (swedish standard). I then try to convert this to a datetime, because it will go into datetime data type in a database.
CultureInfo culture =
new CultureInfo("sv-SE");
DateTime myDate =
Convert.ToDateTime(txtMyDate.Text, culture);
This is done in a try{}-block, and since it dosn't work it ends up in the catch{}-section saying "Input string was not in a correct format".
None
0 Points
1 Post
date conversion
Oct 17, 2006 09:40 AM|hleijon|LINK
I have a textbox (txtMyDate) in which I enter a date in the format "yyyy-MM-dd" (swedish standard). I then try to convert this to a datetime, because it will go into datetime data type in a database.
CultureInfo culture = new CultureInfo("sv-SE");
DateTime myDate = Convert.ToDateTime(txtMyDate.Text, culture);
This is done in a try{}-block, and since it dosn't work it ends up in the catch{}-section saying "Input string was not in a correct format".
What am I doing wrong?
None
0 Points
79 Posts
Re: date conversion
Oct 17, 2006 12:24 PM|andymarks|LINK
Have you tried DateTime.Parse() ?
Andy.