-5

I am trying to convert a string date into a format for sql datetime.

The format is like: "20140428132222" I think this equates to YYYYMMDDTTTTTT

Charles Morrison
  • 418
  • 1
  • 4
  • 23

3 Answers3

1

use TryParseExact:

 DateTime dt;
 bool valid = DateTime.TryParseExact("20140428132222", "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);

gives 4/28/2014 1:22:22 PM

Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
0

Use DateTime.ParseExact(string, string, IFormatProvider).

Martin Costello
  • 9,672
  • 5
  • 60
  • 72
0

It's helpful to Read the Documentation:

The various constructor overloads can also be useful. You pick out the various bits, convert them to integer values and use the constructor.

Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135