Alternativelly to solution #1 by
BillWoodruff[
^], you can use
DateTime.ParseExact Method (System) | Microsoft Docs[
^] to convert string into proper DateTime.
string sdate = "13.08.2018";
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("DE-de");
string format = "dd.MM.yyyy";
DateTime d = DateTime.ParseExact(sdate, format, ci);
Console.WriteLine($"{d}");
Here is the way to convert string-dates to proper dates via Linq query:
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("DE-de");
string format = "dd.MM.yyyy";
dt = dataGridView1.Rows.Cast<DataGridViewRow>()
.Where(x =>x.Cells[0].Value!=null)
.Select(x => dt.LoadDataRow(new object[]
{
x.Cells[0].Value,
DateTime.ParseExact(x.Cells[1].Value.ToString(), format, ci),
DateTime.ParseExact(x.Cells[2].Value.ToString(), format, ci),
(DateTime.ParseExact(x.Cells[2].Value.ToString(), format, ci) - DateTime.ParseExact(x.Cells[1].Value.ToString(), format, ci)).Days
}, false))
.CopyToDataTable();
dataGridView1.Columns.Clear();
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = dt;