DateTime.ParseExact

Hello,

DateTime dt2 = Convert.ToDateTime(reader["DateCreated"].ToString()); //dt2 = {2015-03-20 01:56:09 PM}

string str_DateCreated = dt2.Day.ToString().PadLeft(2, '0') + "-" + dt2.Month.ToString().PadLeft(2, '0') + "-" + dt2.Year; //str_DateCreated = "20-03-2015"

DateTime DateCreated = DateTime.ParseExact(str_DateCreated, "dd-MM-yyyy", CultureInfo.CurrentCulture); //DateCreated = {2015-03-20 12:00:00 AM}

Why Am I where I started? //Ignore the time though.

Am I doing something wrong? Any suggestions?

I need the value back in DateTime to sort in a Jtable

Thanks in advanced 🙂

by xFrenzy47x via /r/csharp

Leave a Reply