Hi,
I have a data string 'yyyymmddhhmmss' example: '20101001151014', how Do I parse this to date in C#?
Hi,
I have a data string 'yyyymmddhhmmss' example: '20101001151014', how Do I parse this to date in C#?
DateTime.ParseExact
you can use and parse it
DateTime dt = DateTime.ParseExact("20101001151014", "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
DateTime when = DateTime.ParseExact("20101001151014", "yyyyMMddHHmmss",
CultureInfo.InvariantCulture);
Points to note: 24-hour hour is HH; 2-digit month is MM
public DateTime ShortDateStringToDate(string dateText)
{
if (dateText == null)
return DateTime.MinValue;
if (dateText.Length != 14)
throw new ArgumentException();
string dateFormatString = "yyyyMMddHHmmss";
return DateTime.ParseExact(dateText, dateFormatString, CultureInfo.InvariantCulture);
}