visishiat
Viral Ad Creator
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
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.
Creating Application
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application for c#.
Step 2
Do the form just like shown below.
Step 3
Press F7 to open the code editor and create a method for getting the time interval based on minutes.
Step 4
Write the following code to get the interval in minutes when the button is clicked.
For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below
Creating Application
Step 1
Open Microsoft Visual Studio 2015 and create a new windows form application for c#.

Step 2
Do the form just like shown below.

Step 3
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;
- try
- {
- total_hours =
ts.
Hours
*
60
;
- total_minutes =
ts.
Minutes
+
total_hours;
- lst.
Items
.
Add
(
total_minutes)
;
- }
catch
(
Exception ex)
- {
- MessageBox.
Show
(
ex.
Message
)
;
- }
- }
Step 4
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