format date string

I have a string  01012004  which is in format ddmmyyyy


i want to format it so it can be converted to a valide date

I'm trying but doesn't work??

strInDate = string.Format(strInDate,"{0:##/##/####}");  
strOutDate = DateTime.Parse(strInDate);

rourkas1Asked:
Who is Participating?
 
DBrightConnect With a Mentor Commented:
DateTime dtInput = DateTime.ParseExact(sDate, "ddMMyyyy", System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);
0
 
nitrogenxCommented:
outDate = inDate.Substring(0, 2) + "/" + inDate.Substring(2, 2) + "/" + inDate.Substring(4);

or

outDate = DateTime.ParseExact(date, "ddMMyyyy",
         System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat).ToShortDateString();
0
All Courses

From novice to tech pro — start learning today.