-1

I have strings in the format

Mar 25 2013 6:30PM

and I want to convert them to datetime objects in the format

2013-03-25 18:30:00

how would I go about doing this?

slavoo
  • 5,798
  • 64
  • 37
  • 39
user517406
  • 13,623
  • 29
  • 80
  • 120

2 Answers2

3

Try this

DateTime dt
CultureInfo provider = CultureInfo.InvariantCulture;
System.Globalization.DateTimeStyles style = DateTimeStyles.None;
DateTime.TryParseExact("Mar 25 2013 6:30PM", "MMM d yyyy h:mtt", provider, style, out dt);
Rajeev Kumar
  • 4,901
  • 8
  • 48
  • 83
2

you can use:

 var date = DateTime.Parse("Mar 25 2013 6:30PM");

 Console.WriteLine(date.ToString()); /*This will output the date in the required format */
Shai Aharoni
  • 1,955
  • 13
  • 25