Convert TimeSpan from format “hh:mm:ss” to “hh:mm”

You need to convert your data to TimeSpan and then use format:"hh\:mm"

string test ="08:00:00";
TimeSpan ts = TimeSpan.Parse(test);
Console.Write(ts.ToString(@"hh\:mm"));

In your case:

var test = dataRow.Field<TimeSpan>("fstart").ToString(@"hh\:mm"));

Remember to escape the colon :

You may see: Custom TimeSpan Format Strings

Leave a Comment