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 number of months between two dates using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="sureshMGR"> sureshMGR</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">From : &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtFrom&#34; Text=&#34;03/01/2019&#34; /&gt; &lt;br /&gt; To : &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtTo&#34; Text=&#34;04/13/2019&#34; /&gt; &lt;br /&gt; &lt;asp:Button Text=&#34;Submit&#34; runat=&#34;server&#34; ID=&#34;btnCalculate&#34; OnClick=&#34;Calcalte&#34; /&gt;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Calcalte(object sender, EventArgs e) { DateTime fromDate = Convert.ToDateTime(txtFrom.Text); DateTime toDate = Convert.ToDateTime(txtTo.Text); double month = Math.Round((toDate.Subtract(fromDate).TotalDays) / 30, 1); ScriptManager.RegisterStartupScript(this, this.GetType(), &#34;CropImage&#34;, &#34;alert(&#39;Total Months are : &#34; + month + &#34;&#39;);&#34;, true); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Calcalte(ByVal sender As Object, ByVal e As EventArgs) Dim fromDate As DateTime = Convert.ToDateTime(txtFrom.Text) Dim toDate As DateTime = Convert.ToDateTime(txtTo.Text) Dim month As Double = Math.Round((toDate.Subtract(fromDate).TotalDays) / 30, 1) ScriptManager.RegisterStartupScript(Me, Me.GetType(), &#34;CropImage&#34;, &#34;alert(&#39;Total Months are : &#34; &amp; month &amp; &#34;&#39;);&#34;, True) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/YC3KEC3.gif" alt="" width="255" height="266" /></p>https://www.aspforums.net:443/Threads/190524/Calculate-number-of-months-between-two-dates-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/190524/Calculate-number-of-months-between-two-dates-using-C-and-VBNet-in-ASPNet/Mon, 15 Apr 2019 02:00:12 GMT