Convert String Column To DateTime In DataTable

  • Thread starter Thread starter IndigoMontoya
  • Start date Start date
I

IndigoMontoya

Guest
We are populating a DataTable like the below - taking a datetime field and populating it into a String.


How should this code be edited to keep the DateTime value and insert into the DataTable?

DataTable dtData = new DataTable();
DataRow newRow = new DataRow();

dtData.Columns.Add("HireDate", typeof(string));

DateTime d1 = Convert.ToDateTime(listItem["Hire_Date_Main"]);
if (String.Format("{0:MM/dd/yyyy}", date) != "1/1/0001")
newRow["HireDate"] = d1;

dtData.Rows.Add(newRow);

Continue reading...
 
Back
Top