• We just launched and are currently in beta. Join us as we build and grow the community.

How to Get the Time Interval Based on Minutes in C#

visishiat

Viral Ad Creator
V Rep
0
0
0
Rep
0
V Vouches
0
0
0
Vouches
0
Posts
165
Likes
149
Bits
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#.
creating_application_c_3.png

Step 2

Do the form just like shown below.
ps_form1.png

Step 3

Press F7 to open the code editor and create a method for getting the time interval based on minutes.

  1. private

    void

    get_minutes(

    TimeSpan ts,ListBox lst)
  2. {
  3. int

    total_minutes, total_hours;

  4. try
  5. {
  6. total_hours =

    ts.

    Hours

    *

    60

    ;
  7. total_minutes =

    ts.

    Minutes

    +

    total_hours;

  8. lst.

    Items

    .

    Add

    (

    total_minutes)

    ;

  9. }

    catch

    (

    Exception ex)
  10. {
  11. MessageBox.

    Show

    (

    ex.

    Message

    )

    ;
  12. }
  13. }


Step 4

Write the following code to get the interval in minutes when the button is clicked.

  1. private

    void

    button1_Click(

    object

    sender, EventArgs e)
  2. {
  3. TimeSpan ts;
  4. DateTime date_from,date_to;

  5. date_from =

    DateTime.

    Parse

    (

    dtp_From .

    Text

    )

    ;
  6. date_to =

    DateTime.

    Parse

    (

    dtp_To .

    Text

    )

    ;
  7. ts =

    date_to.

    Subtract

    (

    date_from)

    ;

  8. get_minutes(

    ts, listBox1)

    ;

  9. }

For any questions about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
Or feel free to comment below

 

452,158

323,328

323,337

Top