Solved

How to Get total minutes between two hours

Posted on 2016-11-22
4
51 Views
Last Modified: 2016-11-22
Hi,

How can get the total minutes between two hours for ex. one person get in at 11:53 h and exit at 12:10 h from one place. In this case the difference is 17 minutes.

best regards
0
Comment
Question by:rflorencio
  • 2
4 Comments
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 41897328
HJI,

pls try
        DateTime a = new DateTime(2010, 05, 12, 11, 53, 00);
        DateTime b = new DateTime(2010, 05, 12, 12, 10, 00);
        Console.WriteLine(b.Subtract(a).TotalMinutes);

Open in new window

Regards
0
 
LVL 28

Accepted Solution

by:
Pawan Kumar earned 250 total points
ID: 41897329
Try..

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim a As DateTime = "2016/01/01 11:53"
        Dim b As DateTime = "2016/01/01 12:10"
        Dim minutesDiff As Integer = DateDiff(DateInterval.Minute, a, b)
End Sub

Open in new window


Output

17 minutes
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 125 total points
ID: 41897415
No points please, and not that it may matter in your case, but note that TotalMinutes returns a decimal value of minutes when (sub)seconds are present, while DateDiff returns an integer value based on the Minute component of the two date values.

/gustav
0
 
LVL 50

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 125 total points
ID: 41897420
you could use then
        DateTime a = new DateTime(2010, 05, 12, 11, 53, 00);
        DateTime b = new DateTime(2010, 05, 12, 12, 10, 00);
        Console.WriteLine(Math.Truncate(b.Subtract(a).TotalMinutes));

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question