Since you are getting a formatted string with DateTime
value, you have to parse it in .Net DateTime
type object, using DateTime.Parse
or DateTime.ParseExact
, (or DateTime.TryParse
variants) like:
string yourStringDate = "30-01-1984";
DateTime dateTimeObj = DateTime.ParseExact(yourStringDate,
"d-M-yyyy",
CultureInfo.InvariantCulture));
(I have used single d
and M
which would work for both single digit Day and Month)
Later add that in your DataTable. like:
DataRow dr = dt.NewRow();
dr["CreateDate"] = dateTimeObj;
I am not sure how you are getting back the date as string, If you are storing DateTime
as string in Database, then its better to use DateTime
type provided by database, instead of keeping dates as string.