1

I have a string in the format:

YYYY-MM-DDDDTHH:MM:SS

This comes from a data feed that I need to import into a SQL Server database so we can do proper reporting off it (sort data by date and time if necessary).

I was going to just split this and manually build the data/time using the parts of the string, but I'm wondering if there's a more elegant way to do this? (Maybe there's an obscure date formatting function I can call that I'm not aware of?)

John Woo
  • 258,903
  • 69
  • 498
  • 492
Tim
  • 4,051
  • 10
  • 36
  • 60
  • possible duplicate of [Converting String to DateTime C#.net](http://stackoverflow.com/questions/919244/converting-string-to-datetime-c-net) – O. R. Mapper Sep 14 '12 at 14:28

2 Answers2

8

use DateTime.ParseExact for this,

Example

DateTime result = DateTime.ParseExact("2012-09-24", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);

sp in your case the format should be

YYYY-MM-DDDDTHH:MM:SS
John Woo
  • 258,903
  • 69
  • 498
  • 492
1

Use DateTime.Parse or DateTime.ParseExact.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536