convert datetime to date format dd/mm/yyyy
First of all, you don't convert a DateTime
object to some format, you display it in some format.
Given an instance of a DateTime
object, you can get a formatted string in that way like this:
DateTime date = new DateTime(2011, 2, 19);
string formatted = date.ToString("dd/M/yyyy");
As everyone else said, but remember CultureInfo.InvariantCulture
!
string s = dt.ToString("dd/M/yyyy", CultureInfo.InvariantCulture)
OR escape the '/'.
DateTime dt = DateTime.ParseExact(yourObject.ToString(), "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
string s = dt.ToString("dd/M/yyyy", CultureInfo.InvariantCulture);