I`m trying to convert date from 01/01/2019 02:00:00 into 01/01/2019 datetime object. However, the string is transformed like 01/01/2019 but the try parse exact returns again the first option.
and also, I would like in my view to show the date, but not in 01/01/2019 format. I would like to have 1st Jan 2019
What I`m doing wrong?
Here is my code.
public DateTime ConvertDate(DateTime dt)
{
var datestring = dt.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
DateTime datePostedObj;
DateTime.TryParseExact(datestring,
"MM/dd/yyyy",
null,
DateTimeStyles.None,
out datePostedObj);
return datePostedObj.Date;
}