How to handle negative TimeSpan value in C#?

Sunny Sharma 0

I had problems with casting TimeSpan object to DateTime. Error occured: FormatException (“the input string was not in proper format”).

Code I tried:
DateTime.Parse(record.Field(“Hours”)); // raised error

Here record is a DataRow object and I’m using Linq to Objects to parse the Date.

//Field actual value :”{-06:25:00}”

How did I overcome?
I used .Duration() method of TimeSpan object.



Shared Hosting with Namecheap. Free .Website domain & WhoisGuard

Leave a Reply

Your email address will not be published. Required fields are marked *