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
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
use TryParseExact:
DateTime dt;
bool valid = DateTime.TryParseExact("20140428132222", "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
gives 4/28/2014 1:22:22 PM
It's helpful to Read the Documentation:
In particular, look at the methods
The various constructor overloads can also be useful. You pick out the various bits, convert them to integer values and use the constructor.