How can I convert MM/DD/YYYY HH:MI:SS AM/PM into DD/MM/YYYY using C# ?I am using C#2008.
Thanks
Use TryParseExact
to parse to a DateTime
, then ToString
with a format string to convert back...
DateTime dt;
if (DateTime.TryParseExact(value, "MM/dd/yyyy hh:mm:ss tt",
CultureInfo.InvariantCulture, DateTimeStyles.None,
out dt))
{
string text = dt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
// Use text
}
else
{
// Handle failure
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With