Get number of days difference between 2 strings

Hello all,

I currently am trying to get the number of days between 2 dates which I am given as a string in the yyyyMMdd format.

string_1 = 20201120
string_2 = 20201210
how would i get the number of days between them?

Refer this


Try this code

DateTime startDt = DateTime.ParseExact(“20201120”, “yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulture);
DateTime endDt = DateTime.ParseExact(“20201210”, “yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulture);

TotalCount = (endDt - startDt ).TotalDays


Hello Dughan,
In this video I do a lot of stuff with DateTime:
In your case convert both to DateTime and then you have the difference between DayOfYear ot TimeSpan.

20:05 DateTime to string in multiple ways
23:00 AddDays get DayofWeek
25:40 Convert from String to DateTime
26:20 Compare DateTime

Cristian Negulescu