I have a string which is got from excel which is of the format dd/mm/yyyy hh:mm:ss
The SQL table I have takes smalldatetime
and uses the mm/dd/yyyy hh:mm:ss
way. I have tried the below to convert the format. The below code has error and is not able to convert to date time
//data is coming from dataTable. dataTable is filled from Excel using OLEDB
if (row[5].ToString().Contains('/'))
{
string[] birthday = row[5].ToString().Split('/');
int month, day;
int.TryParse(birthday[0], out day);
int.TryParse(birthday[1], out month);
string newda = month + "/" + day + "/" + birthday[2];
DateTime dt = Convert.ToDateTime(newda, System.Globalization.CultureInfo.InvariantCulture.ToString("MM/dd/yyyy hh:MM:ss");
row[5] = dt;
}
what am I missing ? How to fix this?