Gold
Gold

Reputation: 62434

convert date format

how to convert : 7/30/2010 11:05:53 AM

to : 30/07/2010

Upvotes: 2

Views: 130

Answers (3)

David Basarab
David Basarab

Reputation: 73301

DateTime temp = DateTime.Parse("7/30/2010 11:05:53 AM");

string converted = temp.ToString("dd/MM/yyyy");

-- Using Try Parse ---

// Try Parse is better because if the format is invalid an exception is not thrown.
DateTime temp;

string converted = string.Empty;

if (DateTime.TryParse("7/30/2010 11:05:53 AM", out temp))
{
    // True means Date was converted properly
    converted = temp.ToString("dd/MM/yyyy");
}
else
{
    converted = "ERROR in PARSING";
}

Upvotes: 4

JWL_
JWL_

Reputation: 829

I belive you can use DateTime.Parse("7/30/2010 11:05:53 AM").ToShortDate() (depending on the culture)

Upvotes: 0

šljaker
šljaker

Reputation: 7374

DateTime.ToString("dd/MM/yyyy");

Upvotes: 0

Related Questions