Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 82

# How to Get total minutes between two hours

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
rflorencio
• 2
3 Solutions

Commented:
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);
``````
Regards
0

Database ExpertCommented:
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
``````

Output

17 minutes
0

CIOCommented:
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

Commented:
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));
``````
0

## Featured Post

• 2
Tackle projects and never again get stuck behind a technical roadblock.