Andrew Lackenby Andrew Lackenby - 5 months ago 42
C# Question

Error parsing time with TimeSpan.ParseExact

I'm trying to read in 2 columns from a DataTable that will give me a date and time.

I've tried the line of code:

lastRun = DateTime.ParseExact(row["last_run_date"].ToString(), "yyyyMMdd", CultureInfo.InvariantCulture)
.Add(TimeSpan.ParseExact(row["last_run_time"].ToString().PadLeft(6, '0'), "HHmmss", CultureInfo.InvariantCulture));

The last_run_date part works OK but the time will not parse correctly.


For TimeSpan, "HH" is not a valid format specifier - use "hh" instead.