ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.Calculate difference between two dates in Hours and Minutes in C# and VB.Net<p>Hi <a class="username" rel="nauna"> nauna</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { timecal(&#34;1/aug/2019&#34;, DateTime.Now.ToString()); Response.Write(result); } public string result { get; set; } public void timecal(string startdate, string enddate) { TimeSpan ts = DateTime.Parse(enddate) - DateTime.Parse(startdate); string lbl = &#34;&#34;; if (ts.Days &gt; 0) { lbl = string.Format(&#34;{0} hours: {1} minutes&#34;, ts.Days * 24 + ts.Hours, ts.Minutes); } else { lbl = string.Format(&#34;{0} hours: {1} minutes&#34;, ts.Hours, ts.Minutes); } result = lbl; }</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load timecal(&#34;1/aug/2019&#34;, DateTime.Now.ToString()) Response.Write(result) End Sub Public Property result As String Public Sub timecal(ByVal startdate As String, ByVal enddate As String) Dim ts As TimeSpan = DateTime.Parse(enddate) - DateTime.Parse(startdate) Dim lbl As String = &#34;&#34; If ts.Days &gt; 0 Then lbl = String.Format(&#34;{0} hours: {1} minutes&#34;, ts.Days * 24 + ts.Hours, ts.Minutes) Else lbl = String.Format(&#34;{0} hours: {1} minutes&#34;, ts.Hours, ts.Minutes) End If result = lbl </pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <p>518 hours: 4 minutes</p>, 22 Aug 2019 03:00:16 GMT