How to Get the Time Interval Based on Minutes in C#
Today I’m going to teach you how to get the time interval based on minutes in C#. This procedure is based on my last tutorial which is “How to Get the Hours Interval of Two Given Time in C#”. This program will illustrates how to get the difference of two given time in minutes. This is simple yet powerful method when you are dealing with the time.
Open Microsoft Visual Studio 2015 and create a new windows form application for c#.
Do the form just like shown below.
Press F7 to open the code editor and create a method for getting the time interval based on minutes.
- private void get_minutes(TimeSpan ts,ListBox lst)
- int total_minutes, total_hours;
- total_hours = ts.Hours * 60;
- total_minutes = ts.Minutes + total_hours;
- }catch(Exception ex)
Write the following code to get the interval in minutes when the button is clicked.
- private void button1_Click(object sender, EventArgs e)
- TimeSpan ts;
- DateTime date_from,date_to;
- date_from = DateTime.Parse (dtp_From .Text );
- date_to = DateTime.Parse(dtp_To .Text);
- ts = date_to.Subtract(date_from);
- get_minutes(ts, listBox1);
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below