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 Year Month Day Hour Minute Second between two dates using C# and VB.Net<p>Hi&nbsp;jovceka,</p> <p>Refer below 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) { DateTime currentdate = Convert.ToDateTime(&#34;03-25-2017 07:07:07&#34;); DateTime dob = Convert.ToDateTime(&#34;01-20-2015 06:06:06&#34;); TimeSpan ts = currentdate - dob; DateTime age = DateTime.MinValue + ts; int years = age.Year - 1; int months = age.Month - 1; int days = age.Day - 2; int hours = ts.Hours; int minutes = ts.Minutes; int seconds = ts.Seconds; Response.Write(String.Format(&#34;{0} year/s {1} month/s {2} day/s {3} hour/s {4} minute/s {5} second/s&#34;, years, months, days, hours, minutes, seconds)); }</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) Dim currentdate As DateTime = Convert.ToDateTime(&#34;03-25-2017 07:07:07&#34;) Dim dob As DateTime = Convert.ToDateTime(&#34;01-20-2015 06:06:06&#34;) Dim ts As TimeSpan = currentdate - dob Dim age As DateTime = DateTime.MinValue + ts Dim years As Integer = age.Year - 1 Dim months As Integer = age.Month - 1 Dim days As Integer = age.Day - 2 Dim hours As Integer = ts.Hours Dim minutes As Integer = ts.Minutes Dim seconds As Integer = ts.Seconds Response.Write(String.Format(&#34;{0} year/s {1} month/s {2} day/s {3} hour/s {4} minute/s {5} second/s&#34;, years, months, days, hours, minutes, seconds)) End Sub</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <p>2 year/s 2 month/s 5 day/s 1 hour/s 1 minute/s 1 second/s <strong> </strong></p>https://www.aspforums.net:443/Threads/552934/Calculate-Year-Month-Day-Hour-Minute-Second-between-two-dates-using-C-and-VBNet/https://www.aspforums.net:443/Threads/552934/Calculate-Year-Month-Day-Hour-Minute-Second-between-two-dates-using-C-and-VBNet/Wed, 23 Jan 2019 06:35:17 GMT