c# Difference calculation dates with point separator

Asked

Viewed 55 times

0

I’m trying to calculate the difference between two dates and times, the format they appear in the file is:

day-month-year hour

Example

start time

17.11.17 22:55:12:968

end time

18.11.17 00:31:35:974

I’ve tried several things like:

DateTime dataUm = DateTime.Parse("17.11.17 19:06:35:625"); 
DateTime dataDois = DateTime.Parse("17.11.17 21:56:52:232");

TimeSpan ts = new TimeSpan(dataDois.Ticks-dataUm.Ticks);

But I always get mistakes:


Microsoft Visual Studio

Exception found. This may be caused by an extension.

  • I was going to close as not clear, but I think this solves, because the problem is just the culture or the mask.

  • Change the input values in the file to "17.11.17 22:55:12:968" and "18.11.17 00:31:35:974". I believe that milliseconds should be separated by "." instead of ":". If entry in this format is a requirement, you will have to do the parse for Datetime specifying exactly the input format

  • Good night this data is from a machine, I have to treat them the way they arrive.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.