0

Hi guys I have a little problem with "ParseExact". So i want to parse a Duration-String (read from excel) to a TimeSpan struct.

The Duration in excel looks like this: (0:0:20.0)

To parse this string I programmed this code:

var rawDuration = (string)WorkSheet.Range[startValue + (offset)].Value2;
TimeSpan duration = TimeSpan.ParseExact(rawDuration, durationFormat, null);
return duration;

I have already tested many things for "durationFormat", among others: "(h:m:ss.f)" and "(h:m:ss.f)".

Something similar already works fine for another function.

dateFormat == "(yyyy/MM/dd HH:mm:ss.ff)" || In Excel = (2020/03/30 06:51:00.00)

    public DateTime GetDateTimes(string startValue, int offset, string dateFormat)
    {
        var TimeWithBrackets = (string)WorkSheet.Range[startValue + (offset)].Value2;
        var Time = DateTime.ParseExact(TimeWithBrackets, dateFormat, null);
        return Time;
    }

Do you have a clue, what I do wrong?

Lars
  • 11
  • 2

0 Answers0