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 Total Hours and Minutes from string variable using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="nauna"> nauna</a>,</p> <p>Refer below sample.</p> <p>First you need to calculate total minutes from what time data you have. And then add both calulated total minute.</p> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong> </p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { item.Text = &#34;24:17&#34;.Replace(&#34; hours &#34;, &#34;:&#34;).Replace(&#34;min&#34;, &#34;&#34;).Replace(&#34;hour&#34;, &#34;:&#34;).Replace(&#34;min&#34;, &#34;&#34;); // Calculate total minutes. int itemTotalMinutes = (Convert.ToInt32(item.Text.Split(&#39;:&#39;)[0]) * 60) + Convert.ToInt32(item.Text.Split(&#39;:&#39;)[1]); lblholdingtime.Text = &#34;25:59&#34;.Replace(&#34; hours &#34;, &#34;:&#34;).Replace(&#34;min&#34;, &#34;&#34;).Replace(&#34;hour&#34;, &#34;:&#34;).Replace(&#34;min&#34;, &#34;&#34;); // Calculate total minutes. int holdingtimTotalMinutes = (Convert.ToInt32(lblholdingtime.Text.Split(&#39;:&#39;)[0]) * 60) + Convert.ToInt32(lblholdingtime.Text.Split(&#39;:&#39;)[1]); // Calculate total minutes from both. int totalMinute = itemTotalMinutes + holdingtimTotalMinutes; // Convertint to Hours and minutes. Response.Write((totalMinute / 60) + &#34; Hours : &#34; + (totalMinute % 60) + &#34; minutes&#34;); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load item.Text = &#34;24:17&#34;.Replace(&#34; hours &#34;, &#34;:&#34;).Replace(&#34;min&#34;, &#34;&#34;).Replace(&#34;hour&#34;, &#34;:&#34;).Replace(&#34;min&#34;, &#34;&#34;) Dim itemTotalMinutes As Integer = (Convert.ToInt32(item.Text.Split(&#34;:&#34;c)(0)) * 60) + Convert.ToInt32(item.Text.Split(&#34;:&#34;c)(1)) lblholdingtime.Text = &#34;25:59&#34;.Replace(&#34; hours &#34;, &#34;:&#34;).Replace(&#34;min&#34;, &#34;&#34;).Replace(&#34;hour&#34;, &#34;:&#34;).Replace(&#34;min&#34;, &#34;&#34;) Dim holdingtimTotalMinutes As Integer = (Convert.ToInt32(lblholdingtime.Text.Split(&#34;:&#34;c)(0)) * 60) + Convert.ToInt32(lblholdingtime.Text.Split(&#34;:&#34;c)(1)) Dim totalMinute As Integer = itemTotalMinutes + holdingtimTotalMinutes Response.Write((totalMinute / 60) &amp; &#34; Hours : &#34; &amp; (totalMinute Mod 60) &amp; &#34; minutes&#34;) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <p>50 Hours : 16 minutes</p>https://www.aspforums.net:443/Threads/153190/Calculate-Total-Hours-and-Minutes-from-string-variable-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/153190/Calculate-Total-Hours-and-Minutes-from-string-variable-using-C-and-VBNet-in-ASPNet/Fri, 30 Aug 2019 07:34:24 GMT