ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Calculate Days difference between two dates in C# and VB.Net<p>Hi <a class="username" rel="Tevin"> Tevin</a>,</p> <p><span class="comment-copy">The answer is obviously correct. Since it inclusive both dates so returns a day less in difference. So add 1 to get your result. </span></p> <p><strong><span style="text-decoration: underline;"><span class="comment-copy">C#</span></span></strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { DateTime dt1 = new DateTime(2019, 08, 01); DateTime dt2 = new DateTime(2019, 08, 31); TimeSpan ts = dt2.Subtract(dt1); Response.Write(ts.TotalDays + 1); }</pre> <p><span style="text-decoration: underline;"><strong>VB.Net</strong></span></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim dt1 As DateTime = New DateTime(2019, 8, 1) Dim dt2 As DateTime = New DateTime(2019, 8, 31) Dim ts As TimeSpan = dt2.Subtract(dt1) Response.Write(ts.TotalDays + 1) End Sub</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <p>31</p>https://www.aspforums.net:443/Threads/334695/Calculate-Days-difference-between-two-dates-in-C-and-VBNet/https://www.aspforums.net:443/Threads/334695/Calculate-Days-difference-between-two-dates-in-C-and-VBNet/Fri, 16 Aug 2019 04:11:28 GMT